[英]msbuild fails with type or namespace name missing
I have a C# project (csproj) and a solution (sln), which I want to build via msbuild.exe
.我有一个 C# 项目 (csproj) 和一个解决方案 (sln),我想通过msbuild.exe
构建msbuild.exe
。
$ msbuild.exe foo.sln /m /t:Build /p:Configuration="Release"
This fails with several errors like these here:这失败了,这里有几个错误:
(CoreCompile target) ->
AppComboCommand.cs(9,7): error CS0246: The type or namespace name 'EnvDTE' could not be found
(are you missing a using directive or an assembly reference?) [foo.csproj]
These errors go away after I opened the project in Visual Studio 2019 and then build again through command line again.在 Visual Studio 2019 中打开项目然后再次通过命令行重新构建后,这些错误消失了。 VS seems to generate a few files while opening the project, and I am wondering what I miss here. VS 好像在打开项目的时候生成了几个文件,我想知道我在这里错过了什么。 Is this maybe a dependency problem?这可能是依赖问题吗?
Any help is highly appreciated任何帮助都受到高度赞赏
EnvDTE is just a vs sdk dll for extend visual studio functionality and it is usually stored in the vs local folder. EnvDTE只是用于扩展 Visual Studio 功能的 vs sdk dll,它通常存储在 vs 本地文件夹中。
First, you should make sure that you have installed the Visual Studio extension development
workloads first.首先,您应该先确保已安装Visual Studio extension development
工作负载。 If you use Build Tool for VS2019, you should also remember to check it.如果你使用 VS2019 的 Build Tool,你也应该记得检查它。
Please follow these:请遵循这些:
1) If you reference this dll in the local area, please make sure that you have referenced it by Right-click on project--> Add Reference
-->reference C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\PublicAssemblies\\envdte.dll
. 1)如果你在本地引用了这个dll,请确保你已经通过右键单击项目--> Add Reference
-->引用C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\PublicAssemblies\\envdte.dll
。
This below approach is not recommended, and for vs SDK DLL references, using nuget is risky:不推荐使用以下方法,对于 vs SDK DLL 引用,使用 nuget 是有风险的:
If you use nuget to install it the EnvDTE
which does exist in nuget.org
, when you build it from command line, you should run nuget restore MySolution.sln
first.如果您使用的NuGet安装它EnvDTE
它确实存在于nuget.org
,当你从命令行构建它,你应该运行nuget restore MySolution.sln
第一。 MSBuild Command line will not restore the missing packages and it is not its job. MSBuild 命令行不会恢复丢失的包,这不是它的工作。
So please download nuget.exe first and then add this in script:所以请先下载nuget.exe ,然后在脚本中添加:
$nuget="xxxxx\nuget.exe(the local path of the nuget.exe)"
$nuget restore `xxxxx\MySolution.sln`
Then execute the build process.然后执行构建过程。
2) I found that you use a powershell script to build the project, so please make sure that you use MSBuild for VS2019 not the one of Net Framework( C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\MSBuild.exe
). 2)我发现你使用powershell脚本来构建项目,所以请确保你使用的是VS2019的MSBuild而不是Net Framework( C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\MSBuild.exe
)。
$msbuild.exe="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"
If you install Build Tool for VS2019 , you should use this path:如果你安装了Build Tool for VS2019 ,你应该使用这个路径:
C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.