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

project.GetPropertyValue("TargetPath") returns string.empty #5680

Closed WenyunZou closed 4 years ago

WenyunZou commented 4 years ago

Issue Description

tried to get "TargetPath" of a project programmally.

project.GetPropertyValue("TargetPath")

In dotnetcore project, it returns the correct path. In dotnet standard project, it returns string.empty.

Steps to Reproduce

create a c# dotnetstandard2.0 project A create a c# dotnetstandard2.0 project B create a c# dotnetcoreapp project C

coding in B&C: Project project = new Project(pathToA); string assemblyPath = project.GetPropertyValue("TargetPath");

Expected Behavior

assemblyPath is not string.empty

Actual Behavior

(no problem with A, its Taget Assembly is actually generated)

In B: assemblyPath is string.empty In C: assemblyPath is not string.empty

Analysis

No idea

Versions & Configurations

msbuild -version Microsoft (R) Build Engine version 16.6.0+5ff7b0c9e for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved.

dotnet --version 3.1.103

WenyunZou commented 4 years ago

Might using different Microsoft.Build.dll

For dotnetstandard project (B): XXXX\NET_Framework_472_TargetingPack.4.7.03081.00\tools\v4.0.30319\reference_assemblies\v4.7.2\Microsoft.Build.dll

For dotnetcoreapp project (C): xxxxx.nuget\packages\microsoft.build\16.3.0\lib\netcoreapp2.1\Microsoft.Build.dll

As B&C are in the same solution, here's a list: image

Just a guess.

rainersigwald commented 4 years ago

Can you share a complete repro, including the application you're using to do the evaluation? The references in the image you shared look wrong to me, and adjusting your use of MSBuildLocator might help resolve the problem.

WenyunZou commented 4 years ago

example.zip

Thank you for your reply. I can't share the original one but attached is an example. please open demo.csproj in vs and run it. It prints nothing in the console, though the path to B.dll is expected.

WenyunZou commented 4 years ago

I don't understand which version of dll I was using, might be an old one. But when I replace the Microsoft.Build.dll with the one in 16.3.0 nuget package, the problem solved.

Thank you very much!