[英]Nuget Package restore with git submodule
i have a project where i include 2 submodules from git. 我有一个项目,其中包括来自git的2个子模块。 Both projects have "nuget package restore" enabled, the parent project too.
两个项目都启用了“nuget包恢复”,父项目也是如此。 The package folder in the two included submodules is not checked in, does not exist in checked out projects.
两个包含的子模块中的包文件夹未签入,在签出的项目中不存在。 When building the parent project Nuget tries to restore the packages in the subfolders but into the wrong package folder!
构建父项目时,Nuget尝试将子文件夹中的包还原到错误的包文件夹中!
"C:\Dev\git\oasisdb\odb_oasis_repository\ODB_OASIS_Repository\.nuget\NuGet.exe" install "C:\Dev\git\oasisdb\odb_oasis_repository\odb_oasis_rvm\ODB_OASIS_RVM_EF\ODB_OASIS_RVM_EF\packages.config" -source "" -NonInteractive -RequireConsent -solutionDir "C:\Dev\git\oasisdb\odb_oasis_repository\ODB_OASIS_Repository\ "
Why does nuget not restore in the solution dir of the submodule? 为什么nuget不能在子模块的解决方案目录中恢复?
Thanks 谢谢
Nuget is restoring the package in the opened solution directory. Nuget正在打开的解决方案目录中恢复软件包。
You can edit the .csproj of the submodule project and modify package dll references from : 您可以编辑子模块项目的.csproj并修改包的dll引用:
<ItemGroup>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Rest.ClientRuntime.2.1.0\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
to : 至 :
<ItemGroup>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>$(SolutionDir)\packages\Microsoft.Rest.ClientRuntime.2.1.0\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
Hope this help! 希望这有帮助!
Found the answers: For anyone interrested: 找到答案:对于任何被捕者:
http://www.xavierdecoster.com/how-to-nuget-package-restore-when-sharing-projects-between-solutions http://www.xavierdecoster.com/how-to-nuget-package-restore-when-sharing-projects-between-solutions
and 和
you can use symbolic link: After nuget downloads all packages to solution's packages
directory, create symbolic link in submodule's root directory (names packages
and link to the solution level packages
directory). 您可以使用符号链接:在nuget将所有包下载到解决方案的
packages
目录后,在子模块的根目录中创建符号链接(命名packages
并链接到解决方案级别packages
目录)。 In short - in your startup project add Pre-Build event that creates symbolic link between your solution packages
directory to all your submodules packages
directory: 简而言之 - 在您的启动项目中添加Pre-Build事件,该事件在您的解决方案
packages
目录与所有子模块packages
目录之间创建符号链接:
This is the batch: 这是批次:
SET sourceDir=$(SolutionDir)packages
SET destDir=$(SolutionDir)..\..\submodules\saturn72\src\packages
if not exist %sourceDir% mkdir %sourceDir%
if not exist %destDir% mklink /j %destDir% %sourceDir%
Full explanation and source code: SolutionWithGitSubmodulesAndNuget 完整的解释和源代码: SolutionWithGitSubmodulesAndNuget
If you're using VS2015 Update 1 or later, you can convert your project to use project.json
to fix this . 如果您使用的是VS2015 Update 1或更高版本,则可以将项目转换为使用
project.json
来解决此问题 。
In short: 简而言之:
Uninstall-Package <package name> -Force -RemoveDependencies
for all your packages. Uninstall-Package <package name> -Force -RemoveDependencies
。 You may wanna copy-paste your packages.config
in notepad before you do this. packages.config
复制粘贴到记事本中。 packages.config
from the project, save the project, unload packages.config
,保存项目,卸载 .props
files at the top related to nuget .props
文件都与nuget相关 <Reference>
elements that reference a package <Reference>
元素 .targets
files at the bottom that reference nuget - usually starts with: <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
.targets
文件 - 通常以: <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Add project.json
with: 添加
project.json
:
{
"dependencies": {
},
"frameworks": {
".NETFramework,Version=v4.6.1": {}
},
"runtimes": {
"win": {}
}
}
Finally add your packages again, either by hand under dependencies
or using Install-Package
or with the nuget UI in VS. 最后,在
dependencies
下手动或使用Install-Package
或VS中的nuget UI再次添加包。
I've also had to remove any Microsoft.Bcl.*
packages from my projects because they explicitly look for a packages.config
file. 我还必须从我的项目中删除任何
Microsoft.Bcl.*
包,因为它们显式查找packages.config
文件。
EDIT: this (removing the Microsoft.Bcl.*
packages will give you a compile-time error, even though the project will build fine, because the .targets
file Microsoft.Bcl.Build
adds will still look for packages.config
. 编辑:这(删除
Microsoft.Bcl.*
包将给你一个编译时错误,即使项目将构建正常,因为Microsoft.Bcl.Build
添加的.targets
文件仍将查找packages.config
。
To suppress this, edit your project file and add: 要禁止此操作,请编辑项目文件并添加:
<SkipValidatePackageReferences>true</SkipValidatePackageReferences>
This needs to go to the first <PropertyGroup>
that doesn't have a Condition
attribute set. 这需要转到没有设置
Condition
属性的第一个<PropertyGroup>
。 If there isn't one, just add another at the top, like: 如果没有,只需在顶部添加另一个,如:
<PropertyGroup>
<SkipValidatePackageReferences>true</SkipValidatePackageReferences>
</PropertyGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.