Visual Studio 2017扩展-VSToolsPath不起作用 [英] Visual Studio 2017 extension - VSToolsPath not working

查看:151
本文介绍了Visual Studio 2017扩展-VSToolsPath不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为VS 2017更新一个旧的Visual Studio扩展.它可以从Visual Studio和msbuild进行编译,并且可以在本地计算机上进行调试和发布.

I'm updating an old Visual Studio extension for VS 2017. It compiles fine from Visual Studio and msbuild in debug and release on my local computer.

这是我正在使用的msbuild命令行:

This is the msbuild command line I am using:

msbuild VxCop.sln /p:ToolsHome=C:\ProgramData\chocolatey\bin /p:Configuration=Release /p:Platform="Any CPU"  

但是,在生成计算机(TFS Build 2010)上,使用相同的命令行调用msbuild.exe时,它失败,并显示

However, on the build machine (TFS Build 2010) calling msbuild.exe with the same command line it fails with this error

为了解决此问题,我尝试指定VSToolsPath.我已经尝试过各种方法,例如更改.csproj中的VSToolsPath条目(由于这样做没有效果,因此似乎没有考虑到该条目),并且还在命令行中传递了它:

In order to fix this I am trying to specify VSToolsPath. I've tried various things such as altering the VSToolsPath entry in the .csproj (which seems to not be taken into account since doing this had no effect) and also passing it on the command line:

msbuild VxCop.sln /p:ToolsHome=C:\ProgramData\chocolatey\bin /p:Configuration=Release /p:Platform="Any CPU"  /p:VSToolsPath=Packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\

这会导致一个非常奇怪的错误:

This causes a very strange error:

CopyFilesToOutputDirectory:                                                                                          
  Copying file from "obj\Release\SymCop.dll" to "bin\Release\SymCop.dll".                                            
  SymCop -> H:\src\tools\VisualStudioExtensions\Main\VxCop\source\SymCop\bin\Release\SymCop.dll                      
  Copying file from "obj\Release\SymCop.pdb" to "bin\Release\SymCop.pdb".                                            
Done Building Project "H:\src\tools\VisualStudioExtensions\Main\VxCop\source\SymCop\SymCop.csproj" (default targets).

Done Building Project "H:\src\tools\VisualStudioExtensions\Main\VxCop\VxCop.sln" (Build target(s)) -- FAILED.        

Done Building Project "H:\src\tools\VisualStudioExtensions\Main\VxCop\build.proj" (default targets) -- FAILED.       


Build FAILED.                                                         
    0 Warning(s)                                                      
    0 Error(s)                                                        

实际的扩展项目根本没有出现在日志中,也没有错误.但是构建返回失败,返回代码非零,并且vsix项目似乎未构建(其输出丢失)

The actual extension project isn't appearing in the log at all, and there's no, y'know, errors. But the build returns as failed, the return code is non-zero, and the vsix project seems to not be built (its output is missing)

希望有人提出一些建议

谢谢

对于以后阅读此书的人来说,问题似乎是同一文件中还有一个<Import>,它不在乎我对$(VSToolsPath)的更新.

For those reading this in the future, the problem seemed to be that there was an <Import> further down in the same file which didn't care about my update to $(VSToolsPath).

更改导入后将其修复:

 <Import Project="$(SolutionDir)\packages\Microsoft.VSSDK.BuildTools.15.1.192\tools\VSSDK\Microsoft.VsSDK.targets" 
 />

推荐答案

Visual Studio 2017扩展-VSToolsPath不起作用

Visual Studio 2017 extension - VSToolsPath not working

根据您的脚本,我得到的结果与您相同.在将NuGet软件包Microsoft.VSSDK.BuildTools安装到项目后,将Microsoft.VSSDK.BuildTools.props导入到项目文件中,打开项目文件,您可以在下面的Import中找到:

I got the same result as you based on your scripts. After installed the NuGet package Microsoft.VSSDK.BuildTools to the project, the Microsoft.VSSDK.BuildTools.props will be imported in to project file, open the project file, you can find below Import:

<Import Project="..\packages\Microsoft.VSSDK.BuildTools.15.1.192\build\Microsoft.VSSDK.BuildTools.props" Condition="Exists('..\packages\Microsoft.VSSDK.BuildTools.15.1.192\build\Microsoft.VSSDK.BuildTools.props')" />

然后打开此道具文件,您会注意到以下脚本片段:

Then open this props file, you can notice below scripts snippet:

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Label="VSSDK_NuGet_Configuration">
    <ThisPackageDirectory>$(MSBuildThisFileDirectory)..\</ThisPackageDirectory>
    <VSToolsPath>$(ThisPackageDirectory)\tools</VSToolsPath>
    <VsSDKInstall>$(VSToolsPath)\VSSDK</VsSDKInstall>
    <VsSDKIncludes>$(VsSDKInstall)\inc</VsSDKIncludes>
    <VsSDKToolsPath>$(VsSDKInstall)\bin</VsSDKToolsPath>
  </PropertyGroup>
</Project>

在这种情况下,NuGet程序包使用$(ThisPackageDirectory)\tools覆盖值VSToolsPath.因此,MSBuild将跳过在下一步中在项目文件中设置值设置:

In this case, NuGet package override the value VSToolsPath with $(ThisPackageDirectory)\tools. So MSBuild will skip set the value setting in the next step in the project file:

  <PropertyGroup>
    <MinimumVisualStudioVersion>15.0</MinimumVisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    <NuGetPackageImportStamp>
    </NuGetPackageImportStamp>
  </PropertyGroup>

因为NuGet已经设置了值$(VSToolsPath),所以Condition="'$(VSToolsPath)' == ''"的值将为 False .另外,您可以添加一个目标来检查该值是否已设置,例如:

Because NuGet have already set the value $(VSToolsPath), the value of Condition="'$(VSToolsPath)' == ''" would be False. In addition, you can add a target to check if the value is set, like:

  <Target Name="CheckVSToolsPath" BeforeTargets="Build">
    <Message Text="$(VSToolsPath)"></Message>
  </Target>

您将发现此值设置为:

C:\Users\Admin\Documents\Visual Studio 2017\Projects\VSIXProject2\packages\Microsoft.VSSDK.BuildTools.15.1.192\build\..\\tools

上面的摘要VSToolsPath的值已正确导入,我们不需要在命令行中传递它.

Summary above, the value of VSToolsPath was imported correctly, we do not need to passing it on the command line.

经过深入调查,我发现了先前错误"MSB4226:找不到导入的项目(...)\ VSSDK \ Microsoft.VsSDK.targets"的原因".是在构建服务器上未设置"VisualStudioVersion"的MSBuild属性.

After in-depth investigation, I found the reason for the previous error "MSB4226: The imported project "(...)\VSSDK\Microsoft.VsSDK.targets" was not found." is that the MSBuild property of "VisualStudioVersion" not be set on the build server.

有关详细信息,请参见下面的链接

See below link for detail info Building a VSIX extension with the Visual Studio 2017 Build Tools:

如果打开开发人员命令提示符,则具有完整Visual Studio 2017的计算机和具有Build Tools 2017的计算机会执行的操作.由于未使用它,因此将其作为参数传递给MSBuild脚本.也可以在.csproj文件中定义它,以前的Visual Studio版本会自动执行,而最新版本则不会.

something that a machine with the full Visual Studio 2017 does and that a machine with the Build Tools 2017 does if you open a developer command prompt. Since I was not using it, I passed it as a parameter to the MSBuild script. It can be defined too inside the .csproj file, something that previous Visual Studio versions did automatically but recent versions don’t.

因此,要解决错误"MSBuild4226",您应该在命令行中传递Visual Studio版本:

So to resolve the error "MSBuild4226", you should pass the visual studio version on command line:

msbuild VxCop.sln /p:ToolsHome=C:\ProgramData\chocolatey\bin /p:Configuration=Release /p:Platform="Any CPU" /p:VisualStudioVersion=15.0

使用此命令行后,错误MSBuild 4226已解决.

After using this command line, the error MSBuild 4226 was resolved.

希望这会有所帮助.

这篇关于Visual Studio 2017扩展-VSToolsPath不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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