How do I provide private NuGet feed credentials to an Azure Function? - azure

I am trying to create an Azure function which has dependencies on NuGet packages hosted in a private NuGet feed.
This question describes using a nuget.config file which is uploaded to the app service which hosts the function - my nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyPrivateFeed" value="https://<url to feed>" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
My function is using this config file as expected, but it doesn't have the credentials it needs. The Azure function portal shows the following:
2016-10-04T09:00:55.442 Starting NuGet restore
2016-10-04T09:00:56.926 Restoring packages for D:\home\site\wwwroot\HttpTriggerSqlDb\project.json...
2016-10-04T09:00:58.267 Please provide credentials for: https://<url to feed>
2016-10-04T09:00:58.515 Unable to load the service index for source https://<url to feed>.
2016-10-04T09:00:58.515 Response status code does not indicate success: 401 (Unauthorized).
How do I provide credentials for the private feed?

You should be able to set up your credentials directly in the nuget config file: https://docs.nuget.org/ndocs/schema/nuget.config-file.md#packagesourcecredentials.

Related

Azure App Service - What modified my web.config?

I have an ASP.NET Core website running from Kestrel. It is deployed to Azure App Service in production and another as staging.
I like to configure staging as "production-like" so I set ASPNETCORE_ENVIRONMENTNAME = Production in the Configuration blade of the App Service in the Azure portal. I could see from logs that the code was seeing the environment name as staging still.
It turns out <environmentVariable name="ASPNETCORE_ENVIRONMENTNAME" value="staging" /> is set in the web.config that's on the Azure instance!!
Now, I don't have this set in the web.config or any transforms in my codebase, and I don't use the web.config, in fact I want nothing to do with it or IIS.
My site is deployed via Azure Pipelines. I use environmentName as a build time variable but the YAML only uses it once, to concatenate some text to make up the resource group name.
I then ran dotnet deploy using the same command line as Azure Pipelines runs, but the web.config it writes into the final publish output folder doesn't contain the offending line either.
It was only a few weeks ago I rebuilt and redeployed all my Azure resources. It was all clean, and it's all scripted.
Where on Earth has it come from??!
I'm worried that if I remove it, one day, it'll magically just reappear. It smells very much like someone at Microsoft thought this automagic was a good idea.
Mind you, I've tried to remove it using the App Service Editor and Kudu but I'm not allowed!!
Your app is currently in read only mode because you are running from a package file. To make any changes, please update the content in your zip file and WEBSITE_RUN_FROM_PACKAGE app setting.
So if I'm not setting it, and I'm not allowed to change it, what do I do??
Update 1
I've downloaded the artifacts from Pipelines and the web.config has the setting in place.
The command run, according to the Pipelines log, was this.
dotnet publish --configuration Release --output D:\a\1\s/dotnet-publish-output
But when I run that myself, on my machine, it does not meddle with my web.config.
Wow. So whilst on the school run, it occurred to me that the value that the dotnet command writes into the web.config is correct. How does it know?
The only way it can know is from that environment variable I'm setting in Azure Pipelines and using in my YAML file azureResourceGroup: tz-$(environmentName).
And when I run it on my dev machine vs. running on the Azure build server, that environment variable is not set.
So I set environmentName in the environment on my dev machine before running dotnet publish and, hey presto! It screws up my web.config by adding an environment variable! Amazing.
> $env:environmentName = "undocumented-feature"
> dotnet publish --configuration Release --output C:\DATA\Published
...
> cat C:\DATA\Published\web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\MyWebsiteYeah.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="undocumented-feature" />
</environmentVariables>
</aspNetCore>
<security>
<requestFiltering>
<requestLimits maxUrl="32768" maxQueryString="262144"/>
</requestFiltering>
</security>
</system.webServer>
</location>
</configuration>
<!--ProjectGuid: 3E05D228-D9AF-4782-8E33-1F0E69992750-->
Isn't that dreadful.
So I solved the whole problem with my websites ignoring the variables set in the portal by changing the variable name in Pipelines to hostEnvironmentName.

Error "Unable to load the service index for source" while trying to publish a NuGet package to gitlab.com

I have a private C# project on the gitlab.com and want to create a NuGet package there.
I followed the instruction and created the following Nuget.config file on the solution level.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="gitlab" value="https://gitlab.com/api/v4/project/{my_project_numeric_id_here}/packages/nuget/index.json" />
</packageSources>
<packageSourceCredentials>
<gitlab>
<add key="Username" value="{my_username_in_gitlab}" />
<add key="ClearTextPassword" value="{my_personal_token_with_api_access_here}" />
</gitlab>
</packageSourceCredentials>
</configuration>
Then I used the Visual Studio Package Manager Console and ran the following command:
dotnet nuget push "C:\{path_to_the_package_here}\MyProject.1.0.0.nupkg" --source gitlab
and had the following error:
error: Unable to load the service index for source https://gitlab.com/api/v4/project/{my_project_numeric_id_here}/packages/nuget/index.json.
error: Response status code does not indicate success: 404 (Not Found).
MyProject.1.0.0.nupkg — exists.
Nuget.config — is seen by the command (reflects changes in the file).
Personal Token — I played with different permissions, at least api permission is granted, and all others too.
What is wrong in my actions and how to create a NuGet package from the C# project on GitLab.com?

Azure Role Service can`t deploy - WaHostBootstrapper.exe.config missing

I`m trying to deploy New Azure Service (using SDK 2.9) and encounter the following error:
The file provided is not a valid service package.
Invalid application runtime - a runtime component is missing:/base/x64/WaHostBootstrapper.exe.config.
Screenshot of the error
What did I try:
Tried to package the service and saw "base/x64/WaHostBootstrapper.exe.config" exists and not missing. Screenshot of the Package Folder
Tried to deploy other service from different workload (also SDK 2.9) it works.
Tried to compare the content of WaHostBootstrapper.exe.config between the to mentioned sevices and it was identical
Attaching the contents of the file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0.50727" />
</startup>
<runtime>
<NetFx40_LegacySecurityPolicy enabled="false" />
</runtime>
</configuration>
Any ideas what else can I check or try to do?
Thanks a lot for you help

How to deploy jHipster on Azure App Service, I got 500 request timed out

This guideline provided by Microsoft is for SpringBoot App
https://learn.microsoft.com/en-us/azure/app-service/app-service-deploy-spring-boot-web-app-on-azure
which is essentially:
Create an Azure web app for use with Java
Specify the Java version
Obtain FTP deployment credential
Upload your SpringBoot .JAR along with provided web.config
Restart the web app via Azure portal
The app works!
Instead of .jar, jHipster is producing .war file. Since it is essentially the same (i.e. it can be executed with java -jar), I was hoping the steps would also works for .war.
I've uploaded:
the .war file
the .war.original file
web.config
This is the aforementioned web.config. Please note I've renamed the -jar into -war
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -war "%HOME%\site\wwwroot\gmbgenpro-0.0.1-SNAPSHOT.war"">
</httpPlatform>
</system.webServer>
</configuration>
The app is loading so long that I got the 500 request timed out.
EDIT: I've enabled stdout in the web.config and I got the following from the log files:
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: -war
So it seems I could not use the -war parameter, and I don't know what to do.
To deploy your JHipster project as a WAR file, make sure you build it with spring-boot.repackage.skip option enabled. This will skip building an executable WAR file and simply package the WAR file normally under ${finalName}.war. This way you can deploy your application to a web runtime on Azure automatically configured for you.
To proceed with the deployment, follow these steps:
Add the following Maven Plugin configuration to your main element of your pom.xml:
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<!-- check Maven Central for the latest version -->
<version>1.3.0</version>
<configuration>
<resourceGroup>your-resource-group</resourceGroup>
<appName>your-app-name</appName>
<linuxRuntime>tomcat 9.0-jre8</linuxRuntime>-->
</configuration>
</plugin>
Build your project with the following command, and adjust your profile accordingly:
./mvnw clean package -Pdev -Dspring-boot.repackage.skip=true
Deploy your application:
./mvnw azure-webapp:deploy
For up-to-date information about the Maven Plugin for Azure App Service, check the documentation.

Azure: Web.config Connection String' argument cannot be null or empty

When I try to publish an azure app I get this error.
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4283,5): Error : The 'ibasis_Data_Transfer.mytestdbEntities-Web.config Connection String' argument cannot be null or empty.
My App.Config has a connection string. e.g.
<add name="mytestdbEntities" connectionString="metadata=res://*/mytestappModel.csdl|res://*/mytestappModel.ssdl|res://*/mytestappModel.msl;provider=System.Data.SqlClient;provider connection string="data source=tcp:srv-mytestapp-home.database.windows.net,1433;initial catalog=mytestdb;persist security info=True;user id=blabla;password=blabla;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Don't know where to start looking for solution as error not mentioned on web anywhere in relation to azure.
ibasis - Web Deploy.pubxml
<?xml version="1.0" encoding="utf-8" ?>
<!--
This file is used by the publish/package process of your Web project. You can customize the behavior of this process
by editing this MSBuild file. In order to learn more about this please visit http://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<PublishProvider>AzureWebSite</PublishProvider>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish>http://ibasis.azurewebsites.net</SiteUrlToLaunchAfterPublish>
<LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
<MSDeployServiceURL>ibasis.scm.azurewebsites.net:443</MSDeployServiceURL>
<DeployIisAppPath>ibasis</DeployIisAppPath>
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>
<UserName>$ibasis</UserName>
<_SavePWD>True</_SavePWD>
<_DestinationType>AzureWebSite</_DestinationType>
<PublishDatabaseSettings>
<Objects xmlns="">
<ObjectGroup Name="ibasis_Data_Transfer.ibasisLiveEntities" Order="1" Enabled="False">
<Destination Path="" />
<Object Type="DbCodeFirst">
<Source Path="DBContext" DbContext="ibasis_Data_Transfer.ibasisLiveEntities, ibasis-Data-Transfer" />
</Object>
</ObjectGroup>
</Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
<MSDeployParameterValue Include="$(DeployParameterPrefix)ibasis_Data_Transfer.ibasisLiveEntities-Web.config Connection String" />
</ItemGroup>
<ItemGroup>
<_ConnectionStringsToInsert Include="ibasis_Data_Transfer.ibasisLiveEntities" />
</ItemGroup>
</Project>
Update: As far as i can tell the VS publishing of simple Apps to Azure with 'database first' type entity(edmx) files is not possible.
The auto generated ....Web Deploy.pubxml gets filled with incompatible junk like and "DeployParameterPrefix" which can't be removed and break the build.
I only wanted to call simple Stored Procedure e.g.
myappLiveEntities db = new myappLiveEntities();
db.DoSomeDatabaseWork();
Will do it "old school" method.
I ran into this with a webjob I had been deploying successfully. I wound up deleting the pubxml file under the webjob project PublishProfiles folder and redoing the publish As Azure WebJob.
This issue popped up again when I upgraded to this specific nuget package:
"Microsoft.WindowsAzure.ConfigurationManager" version="3.2.3"
It may be an issue with publishing the webjob before publishing the updated web app or editing the WebApp publish settings ...
Edit: I've since switched to including the web job to the web app publish settings. You can do this by right clicking the project and choosing Add -> Existing Project as Azure Web Job. I no longer publish the WebJob separately.
I believe you need to add a ParameterValue under the MSDeployParameterValue list item. For example,
<ItemGroup>
<MSDeployParameterValue Include="Parameter Name">
<ParameterValue>Parameter Value</ParameterValue>
</MSDeployParameterValue>
</ItemGroup>

Resources