5

I've had trouble building some of the C# projects in a solution I've never had problems with. Building fails with the error that a metadata file is missing. The error description and the msbuild log output at diagnostic level shows some surprising developments. One of the projects I have this problem with is called WpfControlLibrary. It references the following projects in the solution:

Helpers
HAX.Kioszk.Common
HAX.Kioszk.Communication.ImportedServiceContracts
HAX.Kioszk.Data

The solution folder is "D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06".

The build failure error is the following:

Error CS0006 Metadata file 'D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\HAX.Kioszk.Data\bin\Debug\WpfControlLibrary.dll' could not be found (in project WpfControlLibrary; file CSC)

So when I build the WpfControlLibrary project, CSC is looking for a dll that is named after the project in the bin\debug folder of one of the projects the WpfControlLibrary project is referencing.

The build log shows that this is the case with all four project references above. The build is looking for a dll called WpfControlLibrary.dll in their bin\debug folder after building those projects seemingly correctly (the projects are built with the correctly named dll and pdb files). The build error probably only contains one missing dll because it fails at the first error.

However, if I build the whole solution, and I watch the bin\debug folder of the Helpers project, I see that the project is built correctly, and then later during the build, the Helpers.dll file disappears, and there appears a file named WpfControlLibrary.dll (and pdb). The build fails in the end because it does not find Helpers.dll.

The projects the WpfControlLibrary project references have no reference to WpfControlLibrary.

The above result is produced by VS Enterprise 2017 version 15.8.2 with msbuild version 15.8.168.64424. I've recently updated VS, and returned to this solution after working on others for a while, so I can't tell if the update broke it.

I tried building the problematic projects on the same computer using VS Community 2017 version 15.2 with msbuild version 15.1.1012.6693, which builds them fine.

The project also builds fine on other computers with various other versions of VS and msbuild.

I don't know much about msbuild but I compared the Enterprise and the Community build logs, and it seems that the dll names turn sour in the former after the following lines:

Task Parameter:
1>      Properties=
1>          Configuration=Debug
1>          Platform=AnyCPU (TaskId:12)
1>  Global Properties: (TaskId:12)
1>    Configuration=Debug (TaskId:12)
1>    Platform=AnyCPU (TaskId:12)
1>  Removing Properties for project "..\Helpers\Helpers.csproj": (TaskId:12)
1>    TargetFramework (TaskId:12)
1>  Removing Properties for project "..\HAX.Kioszk.Common\HAX.Kioszk.Common.csproj": (TaskId:12)
1>    TargetFramework (TaskId:12)
1>  Removing Properties for project "..\HAX.Kioszk.Communication.ImportedServiceContracts\HAX.Kioszk.Communication.ImportedServiceContracts.csproj": (TaskId:12)
1>    TargetFramework (TaskId:12)
1>  Removing Properties for project "..\HAX.Kioszk.Data\HAX.Kioszk.Data.csproj": (TaskId:12)
1>    TargetFramework (TaskId:12)

These are missing in the Community build log but then there may be lots of other differences.

I'm not sure it is VS' fault. It may be that a global msbuild file the build process takes build targets and whatnot from went corrupt. I tried repairing VS but it made no difference.

I am linking the build log below.

I have a hunch that I'll be able to resolve this only by removing and reinstalling, or repairing the installed .NET Framework versions. Can I do that simply from Control Panel / Programs and Features / <.NET Framework version> / Repair in the context menu?

Download the zipped diagnostic-level build log at https://drive.google.com/file/d/1NqLrzkmQhYSoYQxoja76NQp484gWNTHL/view?usp=sharing

UPDATE

The build log references the Microsoft.Common.CurrentVersion.targets file for each project. For instance:

1>Target "GetTargetPathWithTargetPlatformMoniker: (TargetId:19)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets" from project "D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\Helpers\Helpers.csproj" (target "GetTargetPath" depends on it):
1>Added Item(s): 
1>    TargetPathWithTargetPlatformMoniker=
1>        D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\Helpers\bin\Debug\Helpers.dll
1>                CopyUpToDateMarker=D:\Entegro\TFS\Volánbusz TVM\Bugfixes 2018-06\Helpers\obj\Debug\Helpers.csproj.CopyComplete
1>                TargetFrameworkIdentifier=.NETFramework
1>                TargetFrameworkVersion=4.0
1>                TargetPlatformIdentifier=Windows
1>                TargetPlatformMoniker=Windows,Version=7.0
1>Done building target "GetTargetPathWithTargetPlatformMoniker" in project "Helpers.csproj".: (TargetId:19)

If I replace that file with the file that the VS Community build log references, and build the project, it still gives the same error. However, if I clean the project, and then build, it builds it without errors. For VS and msbuild versions, see above. I link the two files below. The file name shows which version they are.

Enterprise: https://drive.google.com/open?id=1MPnAVQxMtjTcuy39pzmLJolIroBaDgMt

Community: https://drive.google.com/open?id=19Jn8UkRaJ5oAFXreXI4IpRKmGrnjtGQ8

I'll try to compile a small solution with projects that shows this behavior.

UPDATE 2

I've created a solution with only the WpfControlLibrary project and its dependencies. You can download it at the following link:

use the updated link under UPDATE 4 below

I simply copied the project folders into a new folder, and added them to the new solution. I had to doctor the csproj files a little because the following section in each of them resulted in the standard .NET 4 project references (System., etc.) showing up in Solution Explorer as not found:

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
  </Target>

My solution was to comment out this part, which resulted in the projects opening correctly. I also removed and re-added the referenced Nuget packages, just in case.

After restoring the NuGet packages, building the solution results in the following error:

Metadata file 'D:\Entegro\VB TVM\Playground\2018-09-04 VS Build Error\BuildFailure\HAX.Kioszk.Data\bin\Debug\WpfControlLibrary.dll could not be found (Project: WpfControlLibrary; File: CSC)

So the error described above is now reproduced.

I managed to get rid of the build error by excluding all xaml files from the WpfControlLibrary project. I built the solution after re-adding them one by one but could not reach a conclusion as to which caused the error because it varied. Once, the build error went away by removing the reference to the HAX.Kioszk.Communication.ImportedServiceContracts project.

I don't think replacing the Microsoft.Common.CurrentVersion.targets file is a decent solution, so I hope someone can come up with a better one. Thanks in advance.

UPDATE 3

VS 15.8.3 just came out. After updating to it, the process of building the sample solution changes a little. The build error is the following:

The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore.  WpfControlLibrary   D:\Entegro\VB TVM\Playground\2018-09-04 VS Build Error\BuildFailure\WpfControlLibrary\WpfControlLibrary.csproj

The error remains in subsequent builds and never goes away, except if I build only the WpfControlLibrary project. Then we're back to the original build error.

Updating to VS 15.8.4 did not fix it, either.

Because these projects have seen many versions of VS come and go since VS 2010, I have a hunch the csproj files may be in an inconsistent state. I'll try creating new projects and add the code files to them.

UPDATE 4

I just created a new solution with new projects, and added the code files to them. Unluckily, the build finishes with the same error. You can download the solution here:

https://drive.google.com/open?id=1oMtwc8aD0kxE6jmtoF05Z5ROZ7diQzUQ

UPDATE 5

This issue probably has nothing to do with the Microsoft.Common.CurrentVersion.targets file because I compared it with another VS Enterprise installation of the same version, and they match.

I'll try uninstalling and reinstalling VS.

UPDATE 6

Some of the projects in the solution used the PostSharp NuGet package version 4.1.23. Updating them to 6.0.27, the most recent version, solved the issue. The solution builds fine again.

Drew
  • 169
  • 1
  • 1
  • 11
  • Could you reproduce this issue with a simple demo? You can share us a sample to reproduce this issue so that we could directly face this issue. It’s hard to reproduce this issue and find out the reason, just based on your description. – Leo Liu Sep 06 '18 at 06:36
  • @LeoLiu-MSFT Download the sample solution from the link under the UPDATE 2 section above. Thanks. – Drew Sep 07 '18 at 09:44
  • I'm wondering if I have the same problem. I'm trying to switch a build process from using devenv to MSBuild. The build is failing because it's copying, say, MySubLibrary's output to MyMainLibrary.dll on the CopyFilesToOutputDirectory step, then deleting MySubLibrary.dll during the IncrementalClean. After that, following projects that depend on MySubLibrary are failing. Really bizarre. This is with MSBuild 15.8.168.64424, which I installed on the build server just yesterday from the web install. – Sorensen Sep 19 '18 at 15:12

1 Answers1

2

Update - it turns out that there are breaking changes in the Visual Studio update, approx 15.8.3, which caused issues using early versions of PostSharp - I think Drew and myself were on 4.x. Updating PostSharp to the latest version, 6.0.27, solved the problem, after putting in the effort to deal with a few breaking changes that introduced in my aspects.

Original post below.

Same problem this week with a project I haven't touched for months. I cloned the repo on Tuesday and NCrunch builds it fine. Yesterday, I updated VS2017 to 15.8.4 and NCrunch still builds it. But... now 4 projects out of the 32 give me a CS0006 when I hit F5. Looking at the verbose build log I see this:

1>Target "ResolveAssemblyReferences" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets" from project "D:\Repos\g\Game.Client.Wpf\Game.Client.Wpf_ftfxk2qp_wpftmp.csproj" (target "PostSharp30InspectReferences" depends on it):  
1>Using "ResolveAssemblyReference" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".  
1>Task "ResolveAssemblyReference"  
1>  TargetFrameworkMoniker:  
1>      .NETFramework,Version=v4.7.2  
1>  TargetFrameworkMonikerDisplayName:  
1>      .NET Framework 4.7.2  
1>  TargetedRuntimeVersion:  
1>      v4.0.30319  
1>  Assemblies:  
1>      System.Core  
1>  AssemblyFiles:  
1>      D:\Repos\g\EntityComponentSystem\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Framework.Unity\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Framework\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Game.Controls.Wpf\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Game.Messages\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Logging.Metrics\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Logging\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\NetCode\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Universe.Client\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Universe.Physics\bin\Debug\Lafs2.dll  
1>      D:\Repos\g\Universe\bin\Debug\Lafs2.dll  
1>      C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.7.2\mscorlib.dll  

The assembly name of the currently building project has replaced the filename of ALL of the items in AssemblyFiles. The CS0006 says it cannot find D:\Repos\g\Universe\bin\Debug\Lafs2.dll when it should be looking for D:\Repos\g\Universe\bin\Debug\Universe.dll.

  • Not fixed in 15.8.5 and doesn't seem to be on the known issues list yet. https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes#15.8.5 – playtime222 Sep 20 '18 at 19:54
  • @Drew - does your project involve PostSharp? Just to eliminate it from our enquiries... – playtime222 Sep 20 '18 at 19:59
  • both broken projects do indeed reference PostSharp version 4.1.23. I kind of thought about mentioning it but I must have forgotten it. But note that, as I wrote, the same projects build happily on the same version of VS on other machines. I don't know why SO won't mention playtime222 even though I include "@playtime222" in my reply. – Drew Sep 20 '18 at 20:22
  • Reported to Microsoft. Sent a of the problem session using the built-in recorder. – playtime222 Sep 20 '18 at 20:25
  • Damn. I was hoping you wouldn't say that... PostSharp is now on version 6+ I may have to do some work on my aspects to bring them up from using 4.2 to 6 and see if the problem repeats. As for you mention problem - I may not have enough Reputation or some other SO bollox :D – playtime222 Sep 20 '18 at 20:27
  • @Drew Also MOST of the 32 projects in the solution use PostSharp - a few test projects don't - the broken ones are the exes at the top of the dependency tree. – playtime222 Sep 20 '18 at 20:33
  • one of my broken projects is an exe, and one is a class library, so project type has probably nothing to do with the error – Drew Sep 20 '18 at 20:35
  • @Drew Reproduced the issue adding one of the aspects used by this solution to all the projects of another one I've been working on. The wpf exe at the top of the dependency tree get it's reference name mangled as above but not any of the dependents. Looking on PostSharp sight now... FYI https://developercommunity.visualstudio.com/content/problem/340520/assembly-names-are-incorrect-when-performing-msbui.html – playtime222 Sep 20 '18 at 20:39
  • Can't get into my account on PostSharp. I've bumped one of my aspect packages to PostSharp 6.0.27 and updated a test project. Same. Damned. Problem. – playtime222 Sep 21 '18 at 08:31
  • @Drew May I suggest adding a postsharp tag to your original question in the meantime while I try to recover my postsharp support account login at the moment to notify them directly. – playtime222 Sep 21 '18 at 08:44
  • @Drew Ooops. It DOES work with PostSharp 6.0.27. My bad. Despite the aspect packages being updated to use 6.0.27, the exe project was stuck on 4.2.28 for some reason. Everything built correctly once all the projects were 6.0.27. – playtime222 Sep 21 '18 at 08:57