我有一个C#项目(csproj)和一个解决方案(sln),我想通过msbuild.exe
进行构建。
$ msbuild.exe foo.sln /m /t:Build /p:Configuration="Release"
此操作失败,并出现以下类似错误:
(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]
在Visual Studio 2019中打开项目然后通过命令行再次进行构建后,这些错误消失了。 VS在打开项目时似乎会生成一些文件,我想知道我在这里错过了什么。这可能是依赖性问题吗?
我们非常感谢您的帮助
答案 0 :(得分:0)
EnvDTE 只是用于扩展Visual Studio功能的vs sdk dll,通常存储在vs本地文件夹中。
首先,应确保首先安装了Visual Studio extension development
工作负载。如果您使用VS2019的构建工具,还应该记住对其进行检查。
请遵循以下步骤:
1)如果您在本地引用此dll,请确保通过右键单击项目-> Add Reference
->引用{{ 1}}。
不建议采用以下方法,对于vs SDK DLL参考,使用nuget会有风险:
如果使用nuget来安装C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PublicAssemblies\envdte.dll
中存在的EnvDTE
,那么从命令行构建它时,应首先运行nuget.org
。 MSBuild命令行不会还原丢失的软件包,这不是它的工作。
因此,请先下载nuget.exe,然后将其添加到脚本中:
nuget restore MySolution.sln
然后执行构建过程。
2)我发现您使用Powershell脚本来构建项目,因此请确保使用MSBuild for VS2019而不是Net Framework($nuget="xxxxx\nuget.exe(the local path of the nuget.exe)"
$nuget restore `xxxxx\MySolution.sln`
)之一。 / p>
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe
如果安装 VS2019生成工具,则应使用以下路径:
$msbuild.exe="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe"