简体   繁体   English

如何在 Visual Studio 中移动 nuget 路径

[英]How to move nuget path in Visual Studio

Issue: I am trying to run a command PM> add-migration testing .问题:我正在尝试运行命令PM> add-migration testing

Detail: I know why I am getting this error.详细信息:我知道为什么会出现此错误。 Due to security reasons, our company doesn't allow us to run any files inside C:\Users\name\... .由于安全原因,我们公司不允许我们运行C:\Users\name\...里面的任何文件。 so init.ps1 is getting blocked since i cant run inside that folder.所以init.ps1被阻止,因为我无法在该文件夹中运行。

To fix, I moved my Visual Studio project code folder to the following path: C:\adminrun\repos .为了修复,我将我的 Visual Studio 项目代码文件夹移动到以下路径: C:\adminrun\repos Here I admin access and I am allow to run any files.我在这里拥有管理员权限,并且可以运行任何文件。 This lets me run project but init.ps1 is still inside C:\Users\name\.nuget\packages (this path is blocked)这让我可以运行项目,但init.ps1仍在C:\Users\name\.nuget\packages中(此路径被阻止)

Question: can I run add-migration command without PM?问题:我可以在没有 PM 的情况下运行add-migration命令吗?

Error:错误:

&: File C:\Users\name.nuget\packages\microsoft.entityframeworkcore.tools\6.0.13\tools\init.ps1 cannot be loaded because its operation is blocked by software restriction policies, such as those created by using Group Policy. &: 文件 C:\Users\name.nuget\packages\microsoft.entityframeworkcore.tools\6.0.13\tools\init.ps1 无法加载,因为其操作被软件限制策略阻止,例如使用组策略创建的那些.

At line:1 char:45在行:1 字符:45

  • ... rgs+=$_}; ... rgs+=$_}; & 'C:\Users\name.nuget\packages\microsoft.entityfram... & 'C:\Users\name.nuget\packages\microsoft.entityfram...
  • CategoryInfo: SecurityError: (:) [], PSSecurityException类别信息:安全错误:(:) [],PSSecurityException
  • FullyQualifiedErrorId: UnauthorizedAccess FullyQualifiedErrorId: UnauthorizedAccess

C:\Users\name\AppData\Roaming\NuGet\NuGet.Config : C:\Users\name\AppData\Roaming\NuGet\NuGet.Config :

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
  ...
</configuration>

在此处输入图像描述

Step 1, change the downloaded NuGet package storage location:第一步,更改下载的NuGet package存放位置:

  1. According to the following file path, find a file named "NuGet.Config", or search for the file directly.根据以下文件路径,找到名为“NuGet.Config”的文件,或者直接搜索该文件。

    C:\Users{system username}\AppData\Roaming\NuGet C:\Users{系统用户名}\AppData\Roaming\NuGet

  2. Open the "NuGet.Config" file, we can see the original file content as follows:打开“NuGet.Config”文件,我们可以看到原文件内容如下:

     xml version="1.0" encoding="utf-8"? <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> packageSources> configuration>
  3. Replace its contents with the following and save:将其内容替换为以下内容并保存:

     xml version="1.0" encoding="utf-8"? <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> packageSources> <config> <add key="globalPackagesFolder" value=" The new path where you want the NuGet package to be stored " /> <add key="repositoryPath" value=" The new path where you want the NuGet package to be stored " /> config> configuration>

Step2, modify the VS offline package reference address: Step2、修改VS离线package参考地址:

  1. According to the following file path, find a file named "Microsoft.VisualStudio.Offline.config", or search for the file directly.根据以下文件路径,找到名为“Microsoft.VisualStudio.Offline.config”的文件,或直接搜索该文件。

    C:\Program Files (x86)\NuGet\Config C:\Program 文件 (x86)\NuGet\Config

  2. Open the "Microsoft.VisualStudio.Offline.config" file, we can see the original file content as follows:打开“Microsoft.VisualStudio.Offline.config”文件,我们可以看到原文件内容如下:

     xml version="1.0" encoding="utf-8"? <configuration> <packageSources> <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\"/> packageSources> configuration>
  3. Replace its contents with the following and save:将其内容替换为以下内容并保存:

     xml version="1.0" encoding="utf-8"? <configuration> <packageSources> <add key="Microsoft Visual Studio Offline Packages" value=" The new path where you want the NuGet package to be stored "/> packageSources> <config> <add key="globalPackagesFolder" value=" The new path where you want the NuGet package to be stored " /> config> configuration>

Step3, verify that the modified new path is successful: Step3、验证修改新路径是否成功:

Re-open a project with VS, uninstall a reference package in the project and reinstall it, find the reference item in the project reference list, right-click to open the property panel, in the "Path" column, we can clearly find the referenced The address has become the new address we just set.用VS重新打开一个项目,卸载项目中的一个引用package重新安装,在项目引用列表中找到引用项,右键打开属性面板,在“路径”栏中,我们可以清楚的找到referenced 的地址就变成了我们刚刚设置的新地址。

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

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