简体   繁体   English

无论如何,Nuget.config都完全忽略了

[英]Nuget.config ignored completely no matter what

I want to specify where the packages are stored on a nuget restore. 我想指定在nuget还原中存储包的位置。 Of course, this is documented on MSDN, and of course, it never works.... 当然,这是在MSDN上记录的,当然,它永远不会工作....

I have a test solution stored in D:\\Development\\Test\\Test.sln 我有一个存储在D:\\ Development \\ Test \\ Test.sln中的测试解决方案

According to their documentation , nuget no longer looks in the .nuget folder inside the solution folder. 根据他们的文档 ,nuget不再查找解决方案文件夹中的.nuget文件夹。 Instead it now looks in the solution folder, or further up the chain. 相反,它现在在解决方案文件夹中查找,或者在链中向上看。 So I could store a nuget.config in 所以我可以存储一个nuget.config

  • D:\\Development\\Test\\Nuget.Config d:\\开发\\测试\\ Nuget.Config
  • D:\\Development\\Nuget.Config d:\\开发\\ Nuget.Config
  • D:\\Nuget.Config d:\\ Nuget.Config

Well, I tried all three of them, and restarted Visual studio more times than I am willing to count. 好吧,我尝试了所有这三个,并重新启动Visual Studio多次,而不是我愿意计算。

I also read, that they did such a crappy job implementing nuget, that typos inside the nuget.config result in silently ignoring the nuget file. 我还读过,他们在实现nuget时做了如此糟糕的工作,nuget.config中的拼写错误导致静默忽略nuget文件。 So I thought, that must be it, I made a typo. 所以我想,那一定是它,我做了一个错字。 So I downloaded nuget.exe (latest stable 5.0.2) and issued the commands to configure nuget to put my packages location where I want it. 所以我下载了nuget.exe(最新的稳定5.0.2)并发出命令配置nuget将我的包位置放在我想要的位置。

nuget config -set repositoryPath=D:\Development\test\packages -configfile ..\nuget.config

This is how the XML looks like: 这就是XML的样子:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="D:\Development\test\packages" />
  </config>
</configuration>

After configuring Nuget.config using nuget.exe, I again tried any of the previous locations (D:\\;D:\\Development\\;D:Development\\Test), restarted visual studio every change of location, richt click solution, choose 'restore nuget packages', and the same result: zero packages are restored to my designated repository path. 在使用nuget.exe配置Nuget.config后,我再次尝试了以前的任何位置(D:\\; D:\\ Development \\; D:Development \\ Test),重新启动visual studio每次更改位置,richt点击解决方案,选择'恢复nuget包',结果相同:零包恢复到我指定的存储库路径。

So as a last attempt, I tried to nuget restore from the command line: 所以作为最后一次尝试,我尝试从命令行进行nuget恢复:

D:\Development\test>nuget restore test.sln -ConfigFile ..\nuget.config
MSBuild auto-detection: using msbuild version '16.1.76.45076' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\bin'.
Restoring packages for D:\Development\test\test\test.csproj...
Restoring packages for D:\Development\test\ClassLibrary1\ClassLibrary1.csproj...
Committing restore...
Committing restore...
Generating MSBuild file D:\Development\test\ClassLibrary1\obj\ClassLibrary1.csproj.nuget.g.props.
Generating MSBuild file D:\Development\test\test\obj\test.csproj.nuget.g.props.
Writing assets file to disk. Path: D:\Development\test\ClassLibrary1\obj\project.assets.json
Writing assets file to disk. Path: D:\Development\test\test\obj\project.assets.json
Restore completed in 603,63 ms for D:\Development\test\ClassLibrary1\ClassLibrary1.csproj.
Restore completed in 603,6 ms for D:\Development\test\test\test.csproj.

NuGet Config files used:
    D:\Development\nuget.config

It even mentions that it uses my nuget.config, but again, ZERO packages restored in my designated package folder! 它甚至提到它使用我的nuget.config,但是再次,ZERO包恢复在我指定的包文件夹中!

I really hope that anybody can tell me in what mysterious way this is supposed to work. 我真的希望任何人都可以告诉我这应该是什么神秘的方式。

This nuget.config stored in a subfolder on E: works for me in Visual Studio 2019 when I load a solution in that subfolder or below: 当我在该子文件夹或下面加载解决方案时,存储在E:上的子文件夹中的这个nuget.config在Visual Studio 2019中适用于我:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="D:\NugetPackages" />
    <add key="globalPackagesFolder" value="D:\NugetPackages" />
    <add key="dependencyVersion" value="Highest" />
  </config>
</configuration>

The key difference is that I also have a globalPackagesFolder entry pointing to the same folder - according to the docs this setting is used by "projects using PackageReference only". 关键的区别在于我还有一个指向同一文件夹的globalPackagesFolder条目 - 根据文档 ,“仅使用PackageReference的项目”使用此设置。 I suggest you try adding a globalPackagesFolder entry. 我建议你尝试添加一个globalPackagesFolder条目。

try this 尝试这个

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <config>
        <add key="repositoryPath" value=@"D:\Development\test\packages" />
    </config>
</configuration>

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

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