In order to have different configurations available for testing of different mobile OS's, I'm trying to create transform files in Rider on (config/appsettings).json files.
On the rider website there's a blog showing how to do exactly that for .config files:
XDT configuration transformations in Rider
Visual Studio has an extension which allows .json transformations called SlowCheetah: SlowCheetah - Visual Studio Marketplace
So far I haven't been able to do this in Rider on .json files.
XDT stands for XML Data Transform, therefore JSON is not supported.
But you can use different JSON files per environment, as stated in the official docs:
// appsettings.json
{
"MyKey": "My default Value",
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
// appsettings.Development.json
{
"MyKey": "My Development Value"
}
// appsettings.Production.json
{
"MyKey": "My Production Value"
}
Please note that this is bound to the new .NET (aka .NET Core, .NET ≥ 5).
Ok, a heads up on my own question ;)
I figured I can alter the .csproj project file to create (but not generate) transform files:
<ItemGroup>
<None Update="Config\Config.Android.json">
<IsTransformFile>true</IsTransformFile>
<DependentUpon>Config.json</DependentUpon>
</None>
<None Update="Config\Config.IOS.json">
<IsTransformFile>true</IsTransformFile>
<DependentUpon>Config.json</DependentUpon>
</None>
<None Update="Config\Config.json">
<TransformOnBuild>true</TransformOnBuild>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<TransformOnBuild>true</TransformOnBuild>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="appsettings.IOS.json">
<IsTransformFile>true</IsTransformFile>
<DependentUpon>appsettings.json</DependentUpon>
</None>
<None Update="appsettings.Android.json">
<IsTransformFile>true</IsTransformFile>
<DependentUpon>appsettings.json</DependentUpon>
</None>
</ItemGroup>
Related
My Azure function works, I can debug it, and deploy it no problem. But when I deploy it and it gets built into the release folder I see errors in the obj -> Release/net6.0 folder.
FYI - I deploy by using the Azure extension and in the Azure workspace panel I click on deploy, then choose my resource group and it runs on it's own and deploys no problem.
I'm wondering if it has something to do with the name I gave my project
"Functions" ?
I'll post what I see below.
Here is my .csproj file for the Azure function project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
</ItemGroup>
</Project>
I was having a similar/related problem a week ago (if you ask me to recall it, I'd need to go through heaps of my screenshots). I was able to deploy my Azure function via GitHub but it wouldn't work and I made satisfactory progress by changing (in the Azure Portal) the value of Configuration | Function Runtime Settings | Runtime Version to the value: ~4. However, just today, the portal is warning me to go back to the value: ~3. So, it is just something you might want to try and be prepared to undo.
On a loosely related topic, yesterday I started having problems with deployment again (via GitHub CI/CD). Today, in the Activity Log under a "Sync Web Apps Function Triggers" entry I saw the error: "Encountered an error (BadGateway) from host runtime". A few minutes later it was cleared (and it said it had run for 13 minutes). Now, I'd been in the portal about 15 minutes, so that might have fixed today's issue -- I figured the job was still in the queue and today it was able to pick it up and work it through. By visiting the function in the portal, it must have helped initialize it somehow. Still working on this one. I'll try resetting the Runtime Version value back to the suggested value ~3.
Good luck with your issue. Cheers, Henk.
I have tried replicating your setup (e.g. "Functions" name) on a Mac with Visual Studio details bellow, without any issues however. If you've used any preview version of VS or even Azure Function Extensions, then I suggest you re-create a new project and import your artifacts.
My setup is the following:
Release ID: 1703001972
Git revision: 8eb3c1bb0f14a8e54ee7c227c7047c46cff6ee8c. Build date: 2022-07-12 19:09:28+00
Build branch: release-17.3
Running on .NET 6.0.5 (64-bit)
Operating System: Mac OS X 12.4.0
Darwin 21.5.0 Darwin Kernel Version 21.5.0
In dotnet5 (function v3) we could fetch the metadata from FunctionContext by calling functionContext.BindingContext.BindingData.TryGetValue("Metadata", out var meta);
However dotnet 6 (v4) does not seem to have this option.
Azure function v3 (.net5)
Can anyone help me out by providing the correct implementation for the new dotnet 6 (v4) functions
To use .net6 with Function V4 we need VS 2022 environment or VS CODE .
I have tried with one simple blobtrigger azure function running with .net 5 and it works fine to fetch the meta data.
using System;
using System.IO;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Logging;
namespace testfuncapp
{
public static class Function1
{
[Function("Function1")]
public static void Run([BlobTrigger("test/{name}", Connection = "AzureWebJobsStorage")] string myBlob, string name,
FunctionContext context)
{
var logger = context.GetLogger("Function1");
logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name} \n Data: {myBlob}");
}
}
}
OUTPUT:-
And the same code we have tried with .net 6 environment and its works fine as well.
To do that Open VS CODE and update the .csproj file with .net 6 and function runtime version to V4
Install Function runtime v4 in your local .
NOTE: We need to install only one runtime version at our end.
Update .csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.2.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.5.2" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
And update the settings.json file to .net 6 and function runtime to V4 then save it .
And then use the command as below:
1- dotnet restore
2- dotnet build
3- func host start
OUTPUT:-
For more information please refer the below links:
BLOG : Migration from Asp.Net Core 5.0 to 6.0
MS Q&A : Migrating Auzre Function runtime version from 3.x to 4.x not working in VS 2019
I'm using libsodium 0.10.0.0 package to implement password hashing.
After installing the nuget package the entries are created in package.config and project file as below:
<Reference Include="Sodium, Version=0.10.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\libsodium-net.0.10.0\lib\Net40\Sodium.dll</HintPath>
</Reference>
The following Error occur after the build:
Severity Code Description Project File Line Suppression State
Error Could not copy the file "C:\Projects\GIT\EP2\ep2-api.git\Applications\AMS\packages\runtimes\win-x86\native\libsodium.dll" because it was not found. Ace.Ams.Web
In order to fix the above error I'm manually adding the below configuration settings in csproj file but still it's not working, and then I tried to manually copy the "runtimes" folder from the libsodium package path to above path and it's working in my local build but my bamboo auto build fails.
<ItemGroup>
<None Include="runtimes\win7-x86\native\**\*">
<PackagePath>runtimes/win7-x86/native/</PackagePath>
<Pack>true</Pack>
</None>
<None Include="runtimes\win7-x64\native\**\*">
<PackagePath>runtimes/win7-x64/native/</PackagePath>
<Pack>true</Pack>
</None>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'net461'">
<None Include="runtimes\osx-x64\native\**\*">
<PackagePath>runtimes/osx-x64/native/</PackagePath>
<Pack>true</Pack>
</None>
<None Include="runtimes\linux-x64\native\**\*">
<PackagePath>runtimes/linux-x64/native/</PackagePath>
<Pack>true</Pack>
</None>
</ItemGroup>
In our DevOps build pipeline, the Build Solution task is properly transforming the "web.base.config" file to "web.config" file, however the artifact file contains only the "web.base.config" and not "web.config".
Our visual studio project file / config file setup looks like this:
…
<Content Include="Web.Base.config" />
<None Include="Web.Debug.config">
<DependentUpon>Web.Base.config</DependentUpon>
<SubType>Designer</SubType>
</None>
<None Include="Web.Dev.config">
<DependentUpon>Web.Base.config</DependentUpon>
<SubType>Designer</SubType>
</None>
<None Include="Web.QA.config">
<DependentUpon>Web.Base.config</DependentUpon>
<SubType>Designer</SubType>
</None>
…
<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''">
<TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>
The msbuild arguments for the Build Solution task look like this:
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"
In the build log file, I can see the transformation taking place successfully.
2019-01-31T21:13:32.1186618Z BeforeBuild:
2019-01-31T21:13:32.1186784Z Transforming Source File: Web.Base.config
2019-01-31T21:13:32.2198256Z Applying Transform File: Web.Dev.config
2019-01-31T21:13:32.4750975Z Output File: Web.config
2019-01-31T21:13:32.5213915Z Transformation succeeded
What do I need to do to get the transformed "Web.config" file to the artifact staging folder?
The issue is resolved - the Web.config file itself had to be part of the CSPROJ file, which it wasn't. Once I added it to the project file, I saw it published/pushed to the web site. I added it to the proj file like this:
...
<Content Include="Web.config" />
<Content Include="Web.Base.config" />
<None Include="Web.Debug.config">
<DependentUpon>Web.Base.config</DependentUpon>
<SubType>Designer</SubType>
</None>
...
I've been able to get Azure functions written in net core to run. I now have added a reference to "WindowsAzure.Storage" and am now getting loaderexceptions when I use the local test environment ("func host start").
I can not use the default table storage binder as I need to upsert records in different tables.
I use precompiled functions and am developing with VSCode on OSX. I can't find any info if this scenario is supported or not. Is it even possible to get external dependencies working with the 2.0 runtime of Azure functions.
The local SDK/runtime is
Azure Functions Core Tools (2.0.1-beta.21)
Function Runtime Version: 2.0.11370.0
My csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.0-beta3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="3.0.0-beta3" />
<PackageReference Include="WindowsAzure.Storage" Version="8.6.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="SearchTwitter\function.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Part of my function
namespace MyProject.Functions
{
public class SearchFunction
{
public async static Task Run(TimerInfo myTimer, Binder binder, TraceWriter log)
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(System.Environment.GetEnvironmentVariable("StorageConnection", EnvironmentVariableTarget.Process));
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable searchMetaDataTable = tableClient.GetTableReference("SearchMetaData");
await searchMetaDataTable.CreateIfNotExistsAsync();
}
}
Function.json
{
"bindings": [
{
"type": "timerTrigger",
"direction": "in",
"schedule": "0 */15 * * * *",
"runOnStartup": true,
"name": "myTimer"
}
],
"scriptFile": "../MyProject.Functions.dll",
"entryPoint": "MyProject.Functions.SearchFunction.Run"
}
The Azure Storage Namespacee is available by default by the Azure Functions hosting environment. You can find more details here: https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-external-assemblies
However, if that’s not what you’re looking for, rest assured that you can consume any external NuGet package by adding it to your Function’s csproj file. For an example on how to do it, check the sample code in this GitHub repo https://github.com/lindydonna/CSharpHttpCore/blob/master/HttpTriggerCore/HttpTriggerCore.csproj
For precompiled functions, WindowsAzure.Storage package comes as sub-dependency of Microsoft.NET.Sdk.Functions, so you don't need to reference it separately.
If you still reference it, and the reference is of a wrong version, you will get conflicts all over the place.
Such care should be taken for any sub-dependency of Microsoft.NET.Sdk.Functions. Otherwise, referencing NuGets is perfectly supported.