11
  1. Install latest stable Visual Studio 2019 16.4.2 (check .NET Core Development and Desktop development with C++ workloads, also make sure that C++/CLI support component in checked).
  2. Create new project with CLR Class Library (.NET Core) template (or CLR Empty Project (.NET Core) if you like).
  3. Compilation via dotnet build command will fail (dotnet build CLRNetCoreTest.sln /p:Configuration=Debug /p:Platform=x86): enter image description here

Compilation via msbuild command is successfull ("%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" CLRNetCoreTest.sln /p:Configuration=Debug /p:Platform=x86).

And that is very strange - I supposed dotnet to be a wrapper built on the top of msbuild..

Sample project is attached (run Build.bat for compilation).

1
  • It's actually a C++ project, dotnet build can't work for C++ projects. Commented Jan 14, 2020 at 8:35

2 Answers 2

5

To add more details:

And that is very strange - I supposed dotnet to be a wrapper built on the top of msbuild.

Agree with Martin, dotnet build for now doesn't support building C++ project, cause dotnet cli doesn't know where to find the necessary C++ xx.targets and xx.props.

Your project is a C++/CLR project(xx.vcxproj) whose target framework is .net core, it has big difference with actual .net core projects(xx.csproj or xx.vbproj), the xx.vcxproj imports many C++ specific files which is not included in .net core sdk.

For example: Go C:\Program Files\dotnet\sdk\xxx you can find many msbuild targets and props files there, but you can't find Microsoft.Cpp.Default.props file. This file comes from C++ workload instead of .net core SDK.

So though dotnet build uses msbuild to build project, it actually doesn't use the same msbuild.exe from VS folder(C:\Program Files (x86)\Microsoft Visual Studio\xxx\xxx\MSBuild\1xxx\Bin\MSBuild.exe). And only the msbuild.exe from VS IDE or MSBuild build tools package can be used to build this project.

In addition:

If your final goal is to build the project in remote server, maybe you're looking for Build Tools for Visual Studio 2019` package.(Free if you've gotten corresponding lisense, more details see this) It doesn't require VS IDE to be installed. (Download link here)

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for clarifying that. BTW we are already using Build Tools for Visual Studio 2019 on our server. But it is not free, it requires the same licensing as Visual Studio
Hmmm, if you've met the requirements of free VS2019 community version, since the build tool is a supplement of it, you can also use the free build tool, no need to install the full VS community 2019 version...
Our company is enterprise and doesn't meet requirements of free VS2019 community version.
Free if you've gotten corresponding lisense could be more suitable! Just update the answer with the useful info you shared, thanks :)
4

C++ projects can only be built with the msbuild.exe shipped with Visual Studio as it relies on Visual Studio's C++ tooling.

The cross-platform dotnet command with its cross-platform MSBuild distribution does not have these tools and as such unable to compile C++ projects. The dotnet command does not use the visual studio version of MSBuild.

2 Comments

Thank you. You were first but Lance Li-MSFT provided more detailed answer.
Hi Martin, do you have experience with solution that has mixed projects, csproj and vcxproj? If I try dotnet build on solution level, vcxproj cannot build. While csproj projects can build... I am in process of converting .net4.8 to .net5.0 and this is one of things that I struggle with.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.