dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.24k stars 1.35k forks source link

"error CS0006: Metadata file '<snip>.dll' could not be found" in project with conditional projectreference #3641

Open LoungeFlyZ opened 6 years ago

LoungeFlyZ commented 6 years ago

In a solution that has a project with a conditional projectreference in one of the projects VS builds fail for me, but dotnet build doesn't.

Steps to reproduce

Here is a sample solution: App.zip

  1. Open the solution with VS 2017 (15.8.0)
  2. Rebuild the solution => fails
  3. Edit LibA.csproj
  4. Comment the existing conditional itemgroup
  5. Uncomment the comment unconditional itemgroup
  6. Rebuild the solution => Success!

Expected behavior

VS build should succeed the same way dotnet build does

Actual behavior

VS build seems to fail with conditional itemgroups and project references.

Environment data

msbuild /version output:

Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

15.8.166.59604

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.400
 Commit:    8642e60a0f

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.400\

Host (useful for support):
  Version: 2.1.2
  Commit:  811c3ce6c0

.NET Core SDKs installed:
  1.1.6 [C:\Program Files\dotnet\sdk]
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.202 [C:\Program Files\dotnet\sdk]
  2.1.400 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 1.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 1.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
rainersigwald commented 6 years ago

What error are you getting? Your repro appears to work for me (I'm on a 15.9 internal build so it's possible something has changed but MSBuild itself hasn't yet):

1>------ Rebuild All started: Project: LibA, Configuration: Debug Any CPU ------
2>------ Rebuild All started: Project: LibC, Configuration: Debug Any CPU ------
2>LibC -> S:\repro\Microsoft\msbuild\issues\3641\LibC\bin\Debug\net452\LibC.dll
1>LibA -> S:\repro\Microsoft\msbuild\issues\3641\LibA\bin\Debug\net452\LibA.dll
2>LibC -> S:\repro\Microsoft\msbuild\issues\3641\LibC\bin\Debug\netstandard2.0\LibC.dll
3>------ Rebuild All started: Project: Lib452, Configuration: Debug Any CPU ------
1>LibA -> S:\repro\Microsoft\msbuild\issues\3641\LibA\bin\Debug\netstandard2.0\LibA.dll
4>------ Rebuild All started: Project: App, Configuration: Debug Any CPU ------
3>Lib452 -> S:\repro\Microsoft\msbuild\issues\3641\Lib452\bin\Debug\net452\Lib452.dll
4>App -> S:\repro\Microsoft\msbuild\issues\3641\App\bin\Debug\net452\App.exe
3>Lib452 -> S:\repro\Microsoft\msbuild\issues\3641\Lib452\bin\Debug\netstandard2.0\Lib452.dll
4>App -> S:\repro\Microsoft\msbuild\issues\3641\App\bin\Debug\netcoreapp2.1\App.dll
========== Rebuild All: 4 succeeded, 0 failed, 0 skipped ==========
LoungeFlyZ commented 6 years ago

Thanks @rainersigwald ... here is what I get. Weirdly this happens after a Clean, then a Rebuild. Right after the rebuild if i just do another Build it completes.

1>------ Build started: Project: LibA, Configuration: Debug Any CPU ------
2>------ Build started: Project: LibC, Configuration: Debug Any CPU ------
2>LibC -> C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\LibC\bin\Debug\netstandard2.0\LibC.dll
1>LibA -> C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\LibA\bin\Debug\netstandard2.0\LibA.dll
2>LibC -> C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\LibC\bin\Debug\net452\LibC.dll
3>------ Build started: Project: Lib452, Configuration: Debug Any CPU ------
1>CSC : error CS0006: Metadata file 'C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\Lib452\bin\Debug\net452\Lib452.dll' could not be found
1>Done building project "LibA.csproj" -- FAILED.
4>------ Build started: Project: App, Configuration: Debug Any CPU ------
4>CSC : error CS0006: Metadata file 'C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\Lib452\bin\Debug\net452\Lib452.dll' could not be found
4>CSC : error CS0006: Metadata file 'C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\LibA\bin\Debug\net452\LibA.dll' could not be found
4>Done building project "App.csproj" -- FAILED.
3>Lib452 -> C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\Lib452\bin\Debug\netstandard2.0\Lib452.dll
3>Lib452 -> C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\Lib452\bin\Debug\net452\Lib452.dll
4>App -> C:\Users\hyperfishadmin\Documents\Visual Studio 2017\Projects\testapp\App\App\bin\Debug\netcoreapp2.1\App.dll
========== Build: 2 succeeded, 2 failed, 0 up-to-date, 0 skipped ==========