How to move nuget path in Visual Studio - asp.net

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>

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.

Related

Dotnet build for private nuget packages fails with "Unable to load the service index for source https://privatenuget.org/F/packages/api/v3/index.json"

I have private nuget repo packages in my solution and when I restore them to build my app in Visual Studio, I get the following error
Severity Code Description Project File Line Suppression State
Error NU1301 Unable to load the service index for source https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json. MyPrivate.Project.Repository C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj 1
With the popular resolution
Nuget connection attempt failed "Unable to load the service index for source"
I tried deleting %AppData%\Roaming\NuGet\NuGet.Config and restarting VS which is not working for me.
My Nuget.Config looks like this.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyGet.orgV3" value="https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json" />
</packageSources>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageManagement>
<add key="format" value="1" />
<add key="disabled" value="False" />
</packageManagement>
</configuration>
Even tried dotnet restore --interactive
But in futile
dotnet restore --interactive
Determining projects to restore...
C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj : error NU1301: Unable to load the service index for source https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json. [C:\Pth\To\source\repos\Project\src\Project.name\Project.csproj]
The repo needs either a password/AzureAAD identity for access and I have logged into the visual studio/terminal with the account I have access to the private repo. I think this is somehow stopping the service index to load, but I have a roadblock to achieving it.
The access to the private package repo:
My Package sources looks like this:
I got a dirty solution.
I decided to use private nuget repo username and password in the Nuget.Config ( at least locally ).
I changed the Nuget.Config to:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyGet" value="https://myprivate.privatenuget.org/F/privatepackages/api/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<MyGet>
<add key="Username" value="myusername" />
<add key="ClearTextPassword" value="mysecretpassword" />
</MyGet>
</packageSourceCredentials>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageManagement>
<add key="format" value="1" />
<add key="disabled" value="False" />
</packageManagement>
</configuration>
I deleted the NuGet.Config from NuGet folder by running
Then, from VS Developer PowerShell Terminal ( because it is not working with the UI build tab ) I ran dotnet restore and the packages got restored.
I'm looking for better answers to avoid passwords in clear text.
The issue was that I messed with the private package repository password that would be prompted when the VS loads the project. If you entered it wrong once, you would never get the package restored.(which is pathetic....as the reason for the restoration failure is not explicit.)
But we can easily solve this by the following steps:
If Visual Studio does not prompt for credentials but the logging Output shows that you did not authenticate correctly, then go to
Control Panel\User Accounts\Credential Manager
and click "Windows Credentials". You can remove stored credentials for nuget/github there. If they become invalid - for example because you regenerated a token - Visual Studio does not prompt to overwrite the invalid credentials, but after removing the credentials and restarting Visual Studio you do get the prompt.
I found it from the stackoverflow answer here: Nuget Package Source is not prompting for credentials

ASP.Net Website - publishing doesn't move all files

When publishing my ASP.Net Website (not a Web Application), the publisher does not include the Web.ConnectionStrings.config file that is next to the web.config. This is required since my web config looks like this:
<connectionStrings configSource="Web.ConnectionStrings.config"/>
How can I get a File System Publish to include files that Visual Studio seems to be ignoring. Please note that this is a website created using [File] > [New Website] in Visual Studio, not a [File] > [New Project] ASP.Net site so Content=Include will not work.
Steps to reproduce:
In Visual Studio: File > New > Website..
Create the Web.ConnectionStrings.config xml document (see ConnectionStrings.config code below).
In the web config link up the Web.ConnectionStrings.config file to the Web.Config file (see Web.config code below)
Publish the website to a folder on your file system, the Web.ConnectionStrings.config doesn't move with the rest of the files.
Web.config:
<configuration>
<connectionStrings configSource="Web.ConnectionStrings.config"/>
..
Web.ConnectionStrings.config:
<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="connString" connectionString="yourConnectionstringhere"/>
</connectionStrings>
The way you publish the website is OK.
But the name of the file into which the connectionstrings get stored must not start with the prefix web., just call it connectionstrings.config instead.
In web.config you put:
<configuration>
<connectionStrings configSource="connectionStrings.config"/>
In the renamed file connectionstrings.config you place:
<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
<add name="connString" connectionString="yourConnectionstringhere"/>
</connectionStrings>
I think this article will help
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/deploying-extra-files
Basically you edit the picture .pubxml file to tell it to include additional files during deployment

VSTS Build With Local Nuget Package From Local Nuget Server

Has anyone had success building an ASPNET5 application in VSTS with a local (not public facing) Nuget server as a feed? Following these steps: https://msdn.microsoft.com/Library/vs/alm/Build/azure/deploy-aspnet5 I can see the script restoring but it always errors out on my local package. I am sure I am configuring something wrong. This is what I have tried:
Add a Nuget Installer task with a arg to my solution and NuGet arguments nugete.exe -source "https://www.nuget.org/api/v2/;http://mynugetserver" (and I tried including no Nuget arguments and including a Nuget.config in the root of my solution). However, the build runs into a an exception saying it cant find the local url: System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The remote name could not be resolved: 'mydomain'. Okay I understand that, but I do I get it to recognize a local URL?
After researching I thought I would have to use the Package Manager Extension for VSTS. So I loaded my packaged on there successfully, but when I included that package URL in my Nuget.config I get a bunch of unauthorized responses from the PreBuild.ps1 because it is trying to look at the VSTS package URL too. And that is where I am now.
Current Nuget.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<config>
<!--DO I NEED TO INCLUDE MY PROXY INFOR HERE I AM BEHIND ONE AT WORK-->
</config>
<bindingRedirects>
<add key="skip" value="False" />
</bindingRedirects>
<activePackageSource>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</activePackageSource>
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Local" value="https://vstsurl/DefaultCollection/_packaging/Local/nuget/v3/index.json" />
<add key="Company Nuget Gallery v2" value="http://mydomain/nuget/api/v2" />
</packageSources>
</configuration>
UPDATE
if I use the Package Manager on VSTS these are the warnings / exceptions all which seem to come from the local feed. not sure why it is using the local feed for all the external packages
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
... other exceptions here
----------
Restore failed
If you are using the build agent hosted by VSTS and your nuget server is in local (Cannot access from internet), the package restore will fail since the build agent cannot find your nuget server. You'd either configure your nuget server so that it can be accessed from internet or deploy your own build agent in the same intranet with your nuget server.

ASP.NET 5 project hosting on IIS

I want to host my ASP.NET 5 project which uses MVC 6 and Entity Framework 7 on Amazon free micro instance.
I can't find any step-by-step manual on how to host ASP.NET 5 projects on IIS, all materials just mention that this is possible but without any guides.
Basically, I'm deploying to local folder and then copying to newly created site, but nothing is working.
Unfortunately, I can't use Azure as it only has one month free trial, not a year.
I'm using Visual Studio 2015 Preview to create ASP.NET 5 projects. I don't think that's difficult to deploy on IIS now.
First publish your website by publishing it as file system in VS 2015 preview, then copy the published folder to your server, create an application in IIS and set the application folder to the wwwroot folder (rather than the root folder), that's all.
Be aware, check if "Microsoft.AspNet.Server.IIS" exists in your website project.json before publishing it.
Edit:
there should be a web.config in wwwroot folder, the content of web.config may be like this (with precompile option when publishing):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta1" />
<add key="kre-package-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta1" />
<add key="kre-clr" value="CoreCLR" />
<add key="kre-app-base" value="..\approot\packages\Rvc.PopUpSite\1.0.0\root" />
</appSettings>
</configuration>
or like this (without precompile option):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta1" />
<add key="kre-package-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta1" />
<add key="kre-clr" value="CoreCLR" />
<add key="kre-app-base" value="..\approot\src\Rvc.PopUpSite" />
</appSettings>
</configuration>
Please notice the value of kre-app-base. Occasionally its value is empty string after publishing in Visual Studio.
I had the same problem with DNX Beta 4.
If someone has the same problem :
You have to target x64 framework (Target DNX Version) when you publish your website in Visual Studio 2015 RC and write "XXX\wwwroot" in Physical Path in your IIS website configuration.
1. First you need to publish the site to the file system:
2. Create a new application in IIS:
3. Unzip the file you've created in step 1 in the website directory from step 2. The folder should look like:
4. You may also need to install DNVM (formerly KVM) and the DNX Runtime Environment (formerly KRE):
Install the DNVM - dotnet version Manager (KVM)
Install the DNX runtime environment inside DNVM (KRE)
You can use the File system publish method. Follow these steps:
1/ Generate in a folder with Visual studio the .dll files
2/ Create a website in IIS manager and give in the path to your folder
I found what I've missed, I need to change url to my public DNS in projct.json file:
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://ec2-54-68-21-4.us-west-2.compute.amazonaws.com/
then after uploading site to Amazon I need to run web.cmd in site root

How to disable source code publishing in ASP.NET 5 apps?

Here is how the deployed content looks like after publishing (on Azure Website):
/approot/packages - NuGet packages
/approot/src - all the source files from the solution
/approot/global.json - a list of global NuGet packages
/wwwroot/bin/AspNet.Loader.dll - the only .dll file in wwwroot folder
/wwwroot/css - front-end code
/wwwroot/lib - front-end code
/wwwroot/web.config - auto-generated
web.config generated during publishing
I'm wondering, how to make it deploy only the compiled output and not the source files?
If you are publishing through VS 2015, then make the following selection to not deploy the source files:
If you are not using VS, then you can use kpm pack command to achieve this. For example, following is the command that VS uses to create the package to deploy (You can enable Detailed logging in Tools | Options | Projects and Solutions | Build and Run, to see this)
"C:\Users\kiranchalla\.kre\packages\kre-clr-x86.1.0.0-beta2-10690\bin\kpm.cmd" pack --runtime KRE-CLR-x86.1.0.0-beta2-10690 --out "C:\Users\kiranchalla\AppData\Local\Temp\AspNetPublish\WebApplication5-91" --wwwroot-out wwwroot --no-source --configuration Release --quiet
Some info:
The effect of the above is that now your application is pre-compiled and you should see a package under the packages folder and the kre-app-base flag in web.config points to this package. Example:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="kpm-package-path" value="..\approot\packages" />
<add key="bootstrapper-version" value="1.0.0-beta1" />
<add key="kre-package-path" value="..\approot\packages" />
<add key="kre-version" value="1.0.0-beta2-10690" />
<add key="kre-clr" value="CLR" />
<add key="kre-app-base" value="..\approot\packages\WebApplication5\1.0.0\root" />
</appSettings>
</configuration>

Resources