无法通过 dotnet build 命令编译模板 C++/CLI (.NET Core 3.1) 项目 [英] Cannot compile template C++/CLI (.NET Core 3.1) project via dotnet build command

查看:84
本文介绍了无法通过 dotnet build 命令编译模板 C++/CLI (.NET Core 3.1) 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 安装最新的稳定版 Visual Studio 2019 16.4.2(检查 .NET Core DevelopmentDesktop development with C++ 工作负载,还要确保C++/CLI 支持 组件已选中).
  2. 使用 CLR 类库 (.NET Core) 创建新项目模板(或 CLR 空项目 (.NET Core),如果您愿意).
  3. 通过 dotnet build 命令编译将失败(dotnet build CLRNetCoreTest.sln/p:Configuration=Debug/p:Platform=x86):
  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):

通过 msbuild 命令编译成功 ("%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe" CLRNetCoreTest.sln/p:Configuration=Debug/p:Platform=x86).

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).

这很奇怪 - 我认为 dotnet 是构建在 msbuild 之上的包装器..

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

示例项目附加(运行 Build.bat 进行编译).

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

推荐答案

添加更多细节:

这很奇怪 - 我认为 dotnet 是一个基于msbuild 的顶部.

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

同意Martindotnet build 目前不支持构建C++项目,因为dotnet cli不知道在哪里可以找到必要的C++ xx.targetsxx.props.

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.

你的项目是一个C++/CLR项目(xx.vcxproj),目标框架是.net core,和实际的.net core项目(xx.csproj 或 xx.vbproj),xx.vcxproj 导入了许多 C++ 特定文件,这些文件未包含在 .net core sdk 中.

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.

例如:Go C:\Program Files\dotnet\sdk\xxx 你可以在那里找到很多 msbuild 目标和道具文件,但是你找不到 Microsoft.Cpp.Default.props 文件.此文件来自 C++ 工作负载,而不是 .net 核心 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.

所以虽然 dotnet build 使用 msbuild 来构建项目,但它实际上并没有使用 VS 文件夹中的相同 msbuild.exe(C:\Program Files (x86)\Microsoft Visual Studio\xxx\xxx\MSBuild\1xxx\Bin\MSBuild.exe).并且只能使用 VS IDE 中的 msbuild.exe 或 MSBuild 构建工具包来构建此项目.

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.

此外:

如果你的最终目标是在远程服务器上构建项目,也许你正在寻找 Build Tools for Visual Studio 2019` 包.(如果你已经获得了相应的 lisense 则免费,更多详细信息参见 this) 它不需要安装 VS IDE.(下载链接此处)

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)

这篇关于无法通过 dotnet build 命令编译模板 C++/CLI (.NET Core 3.1) 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆