简体   繁体   English

使用git子模块时NuGet自动包恢复

[英]NuGet Automatic Package Restore when using git submodules

I am trying to understand if there is any way to rely on Nuget Automatic Package Restore when referencing libraries hosted on Github. 我试图了解在引用Github上托管的库时是否有任何方法可以依赖Nuget自动包恢复。 The problem is that when I add certain library as submodule, it has it's own /packages/ directory. 问题是当我添加某个库作为子模块时,它有自己的/ packages /目录。 But, when I add csproj from that library into my solution since there are no DLLs in /packages/ directory of that submodule, build fails. 但是,当我从该库中添加csproj到我的解决方案,因为该子模块的/ packages /目录中没有DLL,构建失败。

Obviously, easy fix on my machine is to open up .sln file from submodule that I've referenced, do a build. 显然,在我的机器上轻松修复是从我引用的子模块中打开.sln文件,进行构建。 Now, building from my main solution will obviously work since /packages/ folder in submodule is populated. 现在,从我的主解决方案构建显然将起作用,因为填充了子模块中的/ packages /文件夹。 But, this is not something I can do on build server. 但是,这不是我在构建服务器上可以做的事情。

Any way of solving this problem without completely messing up submodule? 有什么方法可以解决这个问题,而不会完全弄乱子模块? I obviously also don't want to change submodule .csproj because that would put it out of sync with origin. 我显然也不想更改子模块.csproj,因为这会使它与origin不同步。 Ideally I would love if I could instruct nuget to pull packages for referenced submodule .csproj in it's own /packages/ directory. 理想情况下,如果我能指示nuget在其自己的/ packages /目录中提取引用的子模块.csproj的包,我会很高兴。

There are two types of automatic package restore. 有两种类型的自动包恢复。 One that is triggered when you build a solution within Visual Studio, and one that is MSBuild based and requires modifying your project to run NuGet.exe restore as part of the build. 在Visual Studio中构建解决方案时触发的一个,以及基于MSBuild的解决方案,需要修改项目以在构建过程中运行NuGet.exe还原。 The MSBuild based restore is enabled by selecting Enable NuGet Package Restore, but this has been deprecated by the NuGet team. 通过选择Enable NuGet Package Restore启用基于MSBuild的还原,但NuGet团队已弃用此功能。

For a build server you would need to do either: 对于构建服务器,您需要执行以下任一操作:

  1. Run NuGet.exe restore for all solutions before you run the build. 在运行构建之前,对所有解决方案运行NuGet.exe restore
  2. Have the NuGet packages restored by MSBuild as the main solution is built. 在构建主要解决方案时,让MSBuild恢复NuGet包。

To restore the NuGet packages with MSBuild you can use the deprecated MSBuild based NuGet package restore or perhaps better is to create a Before.YourSolution.sln.targets file as described in the Ultimate Cross Platform NuGet Restore post. 要使用MSBuild恢复NuGet包,您可以使用基于弃用的基于MSBuild的NuGet包还原,或者更好的是创建一个Before.YourSolution.sln.targets文件,如Ultimate Cross Platform NuGet Restore帖子中所述。 The custom Before....targets file would need to restore packages for the submodule. 自定义Before ....目标文件需要恢复子模块的包。

If you use an MSBuild based restore then one of the benefits is that there is no pre-build step that someone needs to run before building the solution since building the solution does the restore. 如果您使用基于MSBuild的还原,那么其中一个好处是,在构建解决方案之前,没有人需要运行的预构建步骤,因为构建解决方案会执行还原。 One of the problems of the MSBuild based package restore, at least with the one that is enabled when selecting Enable NuGet Package Restore in Visual Studio, is that it can cause problems with NuGet packages that use their own custom MSBuild .targets files. 基于MSBuild的程序包还原的问题之一,至少是在Visual Studio中选择“启用NuGet程序包还原”时启用的问题,是它可能导致使用自己的自定义MSBuild .targets文件的NuGet程序包出现问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM