VSTS Build With Local Nuget Package From Local Nuget Server - asp.net

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.

Related

How to move nuget path in Visual Studio

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.

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

Can't deploy MVC application to IIS - Is my web.config file to blame

I'm struggling to deploy any MVC application onto IIS in a windows 10 environment.
I always get an HTTP error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid. It goes on to suggest there is a problem reading the configuration file.
On a similar post on this site it was suggested that asp.net was not installed but I'm certain that I've done it. I've used the Aspnet_regiis.exe tool and followed the instruction on the link below.
http://www.jammer.biz/enable-asp-net-on-windows-10/
The webconfig file as it came out of visual studio 2017 when I published is as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\HelloWorld.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: e88818e3-e6fd-4105-94cc-5be77ed93582-->
I've not edited it since none of the tutorials I've followed it tell me to.
I've made sure that full access rights on the folder are granted.
Here is the error message as seen from in IIS.
Why is IIS struggling to read my config file?
Thanks in advance.
Ian
I had this same issue when trying to publish a .NetCore2.0 mvc app. The solution can be found here: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/index?view=aspnetcore-2.1&tabs=aspnetcore2x
In my case, I did not have the .NET Core Hosting Bundle installed.

IIS (There was an error while performing this operation)

I receive There was as error while performing this operation error referring to web.config. I follow below configuration:
OS is Windows server 2012 R2 with IIS version 8.5.
URL Rewrite 2.1 module is installed on the machine.
IIS_IUSRS has full access to the directory.
Application Initialization module is installed
.Net CLR Version v4.0.30319 and managed pipeline mode is integrated.
IIS configuration is as below:
Web config is as below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MES.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
</system.webServer>
</configuration>
<!--ProjectGuid: e8701310-485f-4f88-b7d0-1473d07238ac-->
browsing the page I receive below message:
However, when I remove
<aspNetCore processPath="dotnet" arguments=".\MES.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
from web.config I don't receive (There was as error while performing this operation) error but I get below error:
This error occurred for me when trying to double-click on the Logging module for any site with a bad Web.config.
"Bad" includes Web.configs that just have a module IIS doesn't understand - in my case, IIS 10 couldn't understand the <rewrite> tag, and exploded with this extremely confusing error.
You can verify this by just commenting out the contents of your Web.config. The error goes away - then just gradually reduce how much is being commented out until you find the culprit, and track down that solution.
Add <aspNetCore> back and also install ASP.NET Core module on this machine,
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/aspnet-core-module?tabs=aspnetcore2x
I also wrote a tool to better automate such detection,
https://www.jexusmanager.com/tutorials/oob-500.html
This error is typically caused by a reference inside the web.config which cannot be resolved by the dotNet runtime.
If you are using dotNet core, AND you installed the dotNet core hosting bundle BEFORE you configured your server to run IIS you may get this error.
To fix it in this case, you need to re-run the dotNet core hosting bundle installer AGAIN, in "repair mode"
As described in the box entitled "Important", here.
I had this problem with .NET Core 2.1.
I installed 2.1 SDK (v2.1.301) and as Microsoft says Hosting Bundle now installs with SDK, but in my case this did't work.
This problem disappeared only when I installed 2.1 Runtime (v2.1.1) for Hosting Bundle Installer.
Maybe you need to install URL Rewrite
I had same problem.

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