0

我正在更新VS 2017的舊Visual Studio擴展。它在Visual Studio和msbuild編譯時在本地計算機上進行調試和發佈。Visual Studio 2017擴展 - VSToolsPath不能正常工作

這是我使用的MSBuild命令行:調用msbuild.exe它失敗this error

在同一個命令行

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

然而,在構建機上(TFS構建2010)爲了解決這個問題,我試圖指定VSToolsPath。我已經試過各種事情,如在.csproj的改變VSToolsPath條目(這似乎是因爲這樣做沒有效果不被考慮在內),並通過它的命令行:

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\ 

這個原因一個很奇怪的錯誤:

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項目似乎不能建(其輸出丟失)

希望有人有一些建議

感謝

編輯:

對於那些將來閱讀此內容的人,問題似乎是在同一個文件中進一步下降了<Import>,這並不關心我對$(VSToolsPath)的更新。

改變這種進口固定它:

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

回答

2

Visual Studio 2017 extension - VSToolsPath not working

我得到了相同的結果您可以根據您的腳本。安裝NuGet包Microsoft.VSSDK.BuildTools後的項目中,Microsoft.VSSDK.BuildTools.props將在導入到項目文件,打開項目文件,你可以在下面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')" /> 

然後打開該道具文件,可以在下面的腳本代碼片段通知:

<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包覆蓋該值與VSToolsPath$(ThisPackageDirectory)\tools。所以將的MSBuild跳過設置值設置在項目文件中的下一個步驟:

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

因爲的NuGet已經設置的值$(VSToolsPath)Condition="'$(VSToolsPath)' == ''"值將。此外,你可以添加一個目標,以檢查是否該值設置,如:

<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值被正確導入,我們不需要通過命令行傳遞它。

經過深入調查後,我找到了之前錯誤「MSB4226:導入的項目」(...)\ VSSDK \ Microsoft.VsSDK.targets「未找到」的原因。是「VisualStudioVersion」的MSBuild屬性不能在構建服務器上設置。

請參見下面的鏈接查看詳細信息Building a VSIX extension with the Visual Studio 2017 Build Tools

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版本:

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

使用此命令後行,錯誤MSBuild 4226已解決。

希望這會有所幫助。

+0

謝謝利奧。我曾嘗試添加該參數,但無濟於事。問題在於Visual Studio版本插入到構建機器上不存在的路徑中,因爲構建機器只有VS Build Tools,它顯然不會創建該路徑。 編輯:明天當我回到辦公室時,我會提供更多的細節信息,但修復方法是找到實際導入文件並將其更改爲不關心VSToolsPath(基於$(SolutionDir) \包)。 再次感謝 – JohnL

相關問題