簡體   English   中英

NuGet軟件包無法使用gitLab從VS2015恢復

[英]NuGet Package won't restore from VS2015 with GitLab

我一直在尋找有關如何使NuGet如何使用VS2015和GitLab自動還原軟件包的幾天,但我沒有運氣。

場景:我從GitLab克隆了一個空的存儲庫,並使用VS添加了默認的.gitignore和.getattribute文件。 我使用.NET Framework 4.5.2創建了一個HelloWorld控制台應用程序。 我想要自動增加內部版本號,因此我安裝了MSBuild擴展包(在VS的NuGet控制台中鍵入“ Install-Package MSBuild.Extension.Pack”)。 這將修改CSPROJ文件。 然后,我進一步修改了項目文件,以使版本號和修訂號在每個版本上都更新。 項目文件的凈修改部分如下所示:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\MSBuild.Extension.Pack.1.8.0\build\net40\MSBuild.Extension.Pack.targets" Condition="Exists('..\packages\MSBuild.Extension.Pack.1.8.0\build\net40\MSBuild.Extension.Pack.targets')" />
<Import Project="$(MSBuildProjectDirectory)\..\packages\MSBuild.Extension.Pack.1.8.0\tools\net40\MSBuild.ExtensionPack.VersionNumber.targets" />
<Target Name="BeforeBuild" Condition="'$(Configuration)' == 'Release'">
  <AssemblyInfo AssemblyInfoFiles="@(AssemblyInfoFiles)" />
</Target>
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
  <PropertyGroup>
    <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
  </PropertyGroup>
  <Error Condition="!Exists('..\packages\MSBuild.Extension.Pack.1.8.0\build\net40\MSBuild.Extension.Pack.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSBuild.Extension.Pack.1.8.0\build\net40\MSBuild.Extension.Pack.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
     Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

因此,我對其進行了構建,使其表現出預期的效果,並全部檢入。在另一台計算機上,我克隆了存儲庫並打開了解決方案。 該項目將不會加載,並且VS並未嘗試還原任何內容; 這是錯誤:

C:\Users\mwoodard\Source\Repos\c-sharp-commons\HelloConsole\HelloConsole\HelloConsole.csproj : error  : The imported project "C:\Users\mwoodard\Source\Repos\c-sharp-commons\HelloConsole\packages\MSBuild.Extension.Pack.1.8.0\tools\net40\MSBuild.ExtensionPack.VersionNumber.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.  C:\Users\mwoodard\Source\Repos\c-sharp-commons\HelloConsole\HelloConsole\HelloConsole.csproj

我看到很多其他人在NuGet還原方面遇到問題,也有很多解決方案,但是似乎都與最初使用VS2015開始的項目無關。 (有許多解決方案說要更改項目或解決方案的.nuget子目錄中的某些內容……VS2015不會創建此類目錄。)

最重要的是,由於我們的構建計算機將無法運行Visual Studio,因此NuGet還原需要通過MSBuild進行工作。

處理無法打開解決方案的問題:

改用此代碼

<Import Project="..\packages\MSBuild.Extension.Pack.1.8.0\tools\net40\MSBuild.ExtensionPack.VersionNumber.targets" Condition="Exists('..\packages\MSBuild.Extension.Pack.1.8.0\tools\net40\MSBuild.ExtensionPack.VersionNumber.targets')" />

之后,將在Visual Studio中構建時還原軟件包。 在VS中啟用和禁用程序包還原

關於還原的問題:

使用MSBuild集成的還原 ,解決方案中有.nuget文件夾。 由於您不想將.nuget文件夾包括到解決方案文件夾中,並且不想在構建機器(例如CI)上進行構建,因此需要在構建之前還原軟件包。

例如,如果通過TFS / VSTS vNext構建進行構建,則可以添加NuGet恢復構建步驟。 對於gitlab CI構建,您可以在.gitlab-ci.yml文件的before_script部分恢復軟件包。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM