Reputation: 3269
In custom build projects there could be two possible MSBuild frameworks in use. One built with .NET Core and the Visual Studio MSBuild built with .NET Framework. The latter is run always when building from Visual Studio while the former is used by command line build scripts. Due to the fact, that Visual Studio is our IDE of choice and it supports currently only .NET Framework MSBuild we cannot drop support for it (migration to pure .NET Core MSBuild breaks IntelliSense, refactorings, and multiple other VS goodies).
One of the projects in the code base is a C++ vcxproj
which can be built on Windows only with .NET Framework MSBuild while on other platforms it uses make
. C++ project is a dependency for some C# projects and should be built when they are building based on standard MSBuild logic.
Currently it is included into the C# projects in the following way:
<ProjectReference Condition="$(SolutionFileName) == 'Solution.sln'" Include="nativeproject\nativeproject.vcxproj" />
Condition is always true when projects are building from Visual Studio (VS populates this value) and we make it false when building from the build script by calling MSBuild on the project level and building vcxproj separately. However, it does not provide a universal solution that would be based on condition differentiating between .NET Core and .NET Framework MSBuild.
Unfortunately, the best of all worlds where .NET Core MSBuild would be supported by Visual Studio and would be used for vcxproj build is still far away.
Upvotes: 1
Views: 1286
Reputation: 28196
How to find at runtime with well known properties which build of MSBuild is running - .NET Core or .NET Framework.
Try using $(MSBuildRuntimeType)
from this document.
My test:
For test.csproj
in which there's custom target like this:
<Target Name="Test" AfterTargets="build">
<Message Text="value is $(MSBuildRuntimeType)" Importance="high"/>
</Target>
Its value is Full when I use msbuild test.csproj
(.net fx msbuild, same result in VS)
It's value is Core when I use dotnet build test.csproj
(.net core msbuild that contained in .net core SDK)
So it seems to meet your needs if you're trying to get one property to determine which kind of msbuild is being used. Hope it helps and if I misunderstand anything, feel free to correct me.
Upvotes: 4