繁体   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