Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projects that override GetTargetPath have outputs ignored in referencing projects #2183

Closed
agr opened this issue Jun 6, 2017 · 2 comments
Closed

Comments

@agr
Copy link

agr commented Jun 6, 2017

MSBuild version 15.3.255.36604 (Bundled with the VS 2017 15.3.0 Preview 2.0 [26605.1.d15rel]).
Fails to build the following project: https://github.com/NuGet/NuGet.Jobs
The same project builds fine with the MSBuild 15.1.1012.6693 (bundled with VS2017 15.2 (26430.12)).

Steps:

  1. mkdir NuGet.Jobs
  2. cd NuGet.Jobs
  3. git clone https://github.com/NuGet/NuGet.Jobs.git .
  4. git checkout dev
  5. Restore nuget packages (pick one of two):
    • build.cmd (tries to restore nuget packages, then build)
    • nuget restore NuGet.Jobs.sln (needs nuget.exe present)
  6. "C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\15.0\bin\msbuild.exe" .\NuGet.Jobs.sln (msbuild paths may vary)

The first error produced:

Tests.Logger.Job.cs(9,7): error CS0246: The type or namespace name 'NuGet' could not be found (are you missing a using directive or an assembly reference?) [E:\dev\Nuget.Jobs\src\Tests.Logger\Tests.AzureJobTraceListener.csproj]

src\Tests.Logger\Tests.AzureJobTraceListener.csproj references the src\NuGet.Jobs.Common\NuGet.Jobs.Common.csproj which declares the NuGet namespace the compiler complains about, so there shouldn't be any error.

Further examination of the command line it uses to compile the Tests.AzureJobTraceListener.csproj indicates that NuGet.Jobs.Common.dll is not passed as a /reference to the csc.exe. I'm not sure how to dig deeper from this point.

msbuild.log.zip from the build produced with the /flp:v=diag command line argument.

@rainersigwald
Copy link
Member

Thanks for the report!

This appears to be happening because Microsoft.Bcl.Build.targets overrides the GetTargetPath target, which computes the TargetPathWithTargetPlatformMoniker item. #2039 changed the Build target to return that item, rather than the metadata-free $(TargetPath). This causes projects that use the targets from Microsoft.Bcl.Build to have no value returned from the Build target, so projects that reference them don't actually reference the produced assembly.

Workaround

Add this to the bottom of any project that refers to Microsoft.Bcl.Build, just before </Project>:

   <!-- Work around https://github.com/Microsoft/msbuild/issues/2183 remove after VS 15.3 is released -->
   <Target
        Name="Build"
        Condition=" '$(_InvalidConfigurationWarning)' != 'true' "
        DependsOnTargets="$(BuildDependsOn)"
        Returns="$(TargetPath)" />

@rainersigwald
Copy link
Member

FYI @jcouv -- another regression from ref assemblies 😞

FYI @terrajobst -- 15.3 preview 2 will break consumers of https://www.nuget.org/packages/Microsoft.Bcl.Build but a workaround is available.

@rainersigwald rainersigwald changed the title MSBuild from the current VS2017 preview fails to build NuGet.Jobs project Projects that override GetTargetPath have outputs ignored in referencing projects Jun 7, 2017
rainersigwald added a commit to rainersigwald/msbuild that referenced this issue Jun 8, 2017
Some projects (and some NuGet packages) override GetTargetPath, and they
can't be expected to keep up with changes in the metadata now returned
by it.

This change moves the computation of the item returned from GetTargetPath
and Build into its own target (recycling
GetTargetPathWithTargetPlatformMoniker), so that it will still be
created by a project that overwrites GetTargetPath.

Fixes dotnet#2183.
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants