Issue: I am trying to run a command 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\...
. so init.ps1
is getting blocked since i cant run inside that folder.
To fix, I moved my Visual Studio project code folder to the following path: 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)
Question: can I run add-migration
command without PM?
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.
At line:1 char:45
- ... rgs =$_}; & 'C:\Users\name.nuget\packages\microsoft.entityfram ...
- CategoryInfo: SecurityError: (:) [], PSSecurityException
- FullyQualifiedErrorId : UnauthorizedAccess
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>
CodePudding user response:
Step 1, change the downloaded NuGet package storage location:
According to the following file path, find a file named "NuGet.Config", or search for the file directly.
C:\Users{system username}\AppData\Roaming\NuGet
Open the "NuGet.Config" file, we can see the original file content as follows:
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>
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:
According to the following file path, find a file named "Microsoft.VisualStudio.Offline.config", or search for the file directly.
C:\Program Files (x86)\NuGet\Config
Open the "Microsoft.VisualStudio.Offline.config" file, we can see the original file content as follows:
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>
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:
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.