How to Use NuGet Package in VSTS Package Management with Azure Functions? - azure

One of the nice things of Azure Functions is that you can bring your own dependencies with NuGet, npm, etc. If you have an internal NuGet package inside of VSTS Package Management that you want to use as a dependency in your Azure Function, how would you go about including it in your Azure Function usings?
Example: I may want to leverage my internal Data Access Libraries, models, or business logic and then use VSTS Package Management as the way our team manages our internal dependencies. We wouldn't want to publish those out to the public nuget.org gallery 😀
Thanks for the help!

You can reference packages in a private NuGet repository using the information available here.
Once you add your private source to the config file, you can add references to your custom packages following the information outlined here.
(Additional edits from OP...)
Example project.json
{
"frameworks": {
"net46":{
"dependencies": {
"Contoso.Models": "1.2.0",
"Contoso.DAL ": "1.2.0"
}
}
}
}
project.json is added to root folder for your function.
Example nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyVSTSPackageManagementFeed" value="https://contoso.pkgs.visualstudio.com/_packaging/Contoso/nuget/v3/index.json" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<packageSourceCredentials>
<MyVSTSPackageManagementFeed>
<add key="Username" value="me#contoso.com" />
<add key="ClearTextPassword" value="<MyPersonalAccessTokenHere>" />
</MyVSTSPackageManagementFeed>
</packageSourceCredentials>
</configuration>
nuget.config is added to either the root folder for your function or if you want to use them across all of your functions, you can add it to the host level folder.

Related

Adding new handler to the web.config

I am developing a custom web application and try to change the default file extensions used to serve the webpages, I want to register new handler in the web.config so the user can request the pages with new extension: *.do
I am editing the web.config directly because I want to automate the procedure with powershell next.
.......
According to your description, I suggest you could add below web.config try to use below config setting.
<handlers>
<add name="SampleHandler" verb="*"
path="*.do"
type="SampleHandler, SampleHandlerAssembly"
resourceType="Unspecified" />
</handlers>
More details, you could refer to below article:
https://learn.microsoft.com/en-us/iis/configuration/system.webserver/handlers/add

How do I add a service stack license to a .NET core project?

For my service stack license I am used to adding a web config entry
<add key="servicestack:license" ... />
How do I achieve a similar effect in ServiceStack.Core since there is no web config?
The license key can be registered using any of the options listed at: https://servicestack.net/download#register
So while there's no Web.config you can use any of the other 3 options like registering the SERVICESTACK_LICENSE Environment Variable.
Also whilst .NET Core doesn't need to use Web.config or App.config you can still use one in .NET Core in ServiceStack for storing any <appSettings>, e.g:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="servicestack:license" value="{LicenseKey}" />
</appSettings>
</configuration>
But you'll need to register the license key explicitly from the AppSettings with:
using ServiceStack;
public class AppHost : AppHostBase
{
public AppHost()
: base("Service Name", typeof(MyServices).GetAssembly())
{
var licenseKeyText = AppSettings.GetString("servicestack:license");
Licensing.RegisterLicense(licenseKeyText);
}
public override void Configure(Container container)
{
}
}
Or if you don't want to use Web.config you can use any other AppSettings options.

can I load a configSource and then add additional keys in web.config

I have some individual settings I need to apply to specific web sites, and I have a slew of settings that are shared across the websites. I deploy via a continuous integration system.
In my web.config file I have :
<appSettings configSource="App_Data\thisSiteSettings.xml" >
<clear />
<add key="AllSitesSetting" value="ForAllSites" />
</appSettings >
What happens is I get just the settings from thisSiteSettings.xml, and none of the settings from the web.config. I also tried having 2 sections:
<appSettings >
<clear />
<add key="AllSitesSetting" value="ForAllSites" />
</appSettings >
<appSettings configSource="App_Data\thisSiteSettings.xml" >
</appSettings >
which just threw an Error. Finally I tried including the configsource as an "add" node, but that just threw an error as well. (<add configSource="thisSiteSettings.xml" />)
How can I load a few site specific app settings from a seperate file, and the rest from the web.config file?
You can use
<appSettings file="thisSiteSettings.xml">
...
<appSettings />
appSettings in the external file will override settings with the same key in the main configuration file.

Configuration exception thrown when ServiceStack RegisterLicense method is called

When invoking this method, Licensing.RegisterLicense(licenseKey);, I get a initialization exception with the following inner error:
Message=Unrecognized configuration section DbProviderFactories. (C:\Actevis\Development\Actevis.Cloud\SqlLiteTestBed\bin\Debug\SqlLiteTestBed.vshost.exe.Config line 16)
Here is the offending config section:
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
I have tried adding an appsetting section to the app.config file but the same error still appears. Since the DbProviderFactories are not present in the app.config file I assume that the section is injected by ServiceStack.
I am trying to use ServiceStack.Ormlite.SQLite32. This is the nuget package that was installed. I have copied the license file a few times to make sure that there was not problem there.
Thanks
Thanks for your reply. I was able to figure out what was happening:
When installing the ServiceStack.Ormlite.Sqlite32 package, Entity framework and EntityFramework for SQLServer is also installed. There seems to be an issue when using Sqlite and EntryFramework for Sql Server together. I deleted all the entity framework related DGG's from the project and removed the sections from the app.config file. This has fixed the problem.
The issue is that you're Web.config is invalid and the error gets thrown when first trying to access the Web.config, which is what ServiceStack does when it looks for the servicestack:license app setting.
Note: the <DbProviderFactories> should be declared inside <system.data> tags:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
This was caused by the Web.config.transforms in the dependent System.Data.SQLite.x86 package. This could also be a bug in NuGet's web.config.transform as the rule says to add it under <system.data>...</system.data> but it's being added to the top-level creating an invalid Web.config configuration.
The entire config isn't needed for OrmLite so can be removed. I've also reached out to the SQLite maintainer to notify him about this issue so hopefully will be resolved in future issues.
Whilst I'm looking at making changes to OrmLite's Sqlite packages to embed the dlls and remove the dependency to the Sqlite packages that's causing this error.

Azure project lost endpoints and uses default now?

A weird thing happened to my project. I have an Azure WCF project which basically consists of the WebRole and the Azure project. Azure Project contains ServiceDefinition.csdef which in turn contains stuff like endpoint information.
I was playing around in my WebRole and manually set an endpoint there. However, my original issue, due to a stupid user error, did not require this. After I removed the endpoint devinition from web.config, my webrole still gets bound to port 6627 instead of the two endpoints described in my Azure project (80 & 8080). I can't find that port being mentioned anywhere so I'm guessing it is the default.
Here's the part of the web.config that I edited (the removed part is in comments). How do I revert back to getting the configuration from the Azure project?
<system.serviceModel>
<!-- services>
<service name="MyWebRole.MyService" behaviorConfiguration="MyWebRole.BasicUserInformationBehavior">
<endpoint address="" binding="mexHttpBinding" contract="MyWebRole.IMyService"/>
</service>
</services -->
<extensions>
<behaviorExtensions>
<add name="userInformationProcessor" type="MyWebRole.BasicUserInformationBehaviorExtensionElement, MyWebRole, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<bindings />
<client />
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<userInformationProcessor />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
[Edit] More information on the subject! The problem is related to compute emulator no longer starting at all! I don't know why the service works then, but I guess it's running it IIS alone.
I think the solution as mentioned in the comment is that you have to set up the Windows Azure project as the startup project not the webrole.

Resources