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.17k stars 1.34k forks source link

'MSBuildExtensionsPath' appends a '\' backslash in .NET Core mode. #3045

Open Nirmal4G opened 6 years ago

Nirmal4G commented 6 years ago

Steps to reproduce

Set to any simple project in a directory and execute msbuild and dotnet msbuild

:: .NET Framework edition
msbuild /bl /t:Restore
:: .NET Core edition
dotnet msbuild /bl /t:Restore

Examine the .binlog file using MSBuild Structured Log Viewer.

.NET Core mode:

.NET Core mode

.NET Framework mode:

.NET Framework mode

Expected behavior

MSBuildExtensionsPath should not have \ backslash at the end!

Actual behavior

MSBuildExtensionsPath has \ backslash at the end only when run in .NET Core mode!

Environment data

dotnet msbuild /version:

Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

15.5.180.51428

msbuild /version:

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

15.5.180.51428

OS info:

dotnet --info

.NET Command Line Tools (2.1.4)

Product Information:
 Version:            2.1.4
 Commit SHA-1 hash:  5e8add2190

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

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.5
  Build    : 17373eb129b3b05aa18ece963f8795d65ef8ea54
Nirmal4G commented 6 years ago

cc @rainersigwald According to the docs it shouldn't happen, so is it a bug on just .NET Core side?

rainersigwald commented 4 years ago

Can you elaborate on what problem you're observing as a result of this?

Nirmal4G commented 4 years ago

For my scenarios, I use custom sdks in many of my projects. When authoring some of them I found that, in the docs, MSBuildExtensionsPath should not have \ backslash at the end. So, my and possibly others' targets use it like this: $(MSBuildExtensionsPath)SomeFolder\SomeBuildProcess.targets.

When those targets gets shared, let's say, by using msbuild.exe instead of dotnet (ms)build it breaks the build process, since the path becomes like this: C:\Program Files\MSBuildSomeFolder\SomeBuildProcess.targets.

Basically, this a huge behavioral change, sure people are not directly using MSBuildExtensionsPath anymore, but I've seen code in wild, that leads to many build problems, especially for new people familiarizing with dotnet msbuild and authoring custom sdks!

rainersigwald commented 4 years ago

I remain confused, thanks for being patient with me.

If the spec is that it does not have a trailing slash, wouldn't you need to always call it with a slash? To use your example $(MSBuildExtensionsPath)\SomeFolder\SomeBuildProcess.targets?

Nirmal4G commented 4 years ago

It's because .NET Core version don't have the slash. And most people are not looking at the docs, they are learning these from the tools they installed, so if they learn from the tool (.NET Core SDK) that's displaying wrong value, instead of what's in the spec, they write incompatible code, inturn makes the build break!