I have netcoreapp1.1 that I am trying to publish to Azure with WebDeploy. I am able to do dotnet publish and deploy the contents to Azure, but the site just says "You do not have permission to view this directory or page.", which suggests the app is not running.
My previous apps have used net461 as target framework and I have noticed that publishing these (with dotnet publish) have caused a web.config file to be created, which explains how IIS is able to run it, but this does not happen when the target framework is netcoreapp1.1.
The command I have been using to publish is this:
dotnet publish --configuration Release --runtime win7-x64 --output .deploy
Here is my project file:
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
</PropertyGroup>
<ItemGroup>
<Compile Include="Controllers/*.fs" />
<Compile Include="Startup.fs" />
<Compile Include="Program.fs" />
<None Remove="**/*.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup>
</Project>
How am I meant to run a netcoreapp1.1 on Azure? Does it have to be self contained or is it possible to have the Azure App Service run it from dlls?
Edit:
Manually copying a web.config into my publish directory I am able to get the app to run. How can I make dotnet publish create it automatically?
Also, I am still curious about my previous questions.
Add info into you csproj file that you need to copy web.config, like this:
<ItemGroup>
<Content Update="web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
Related
I'm running FunctionApp v4(Azure) and ServiceBusTrigger binding and blob binding, but its not fired, messages are not read from subscription. The app is running ok.
Im running functionapps v3 without any problems, the code is copied and packagereferences is updated. When I run locally, everything works fine.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
<!-- if this is not set, Microsoft optimizes away necessary assemblies for dependency injection and authentication-->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
I am using aspnet core 3.0 and azure function v3-preview with system.data.sqlclient version 4.7.0
When i try to run azure function(on both service queue trigger and time trigger) it gives below error :
The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception. Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found.
I tried solutions from below links but didn't work:
1. Azure Function - System.Data.SqlClient is not supported on this platform
2. https://github.com/Azure/app-service-announcements-discussions/issues/9
I tried using "Microsoft.Data.SqlClient" for aspnetcore 3.0 But still the same exception occurs while running Azure function on Azure portal.
Please help !
Here is csproj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AzureFunctionsVersion>v3-preview</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.30-beta2" />
<PackageReference Include="runtime.native.System.Data.SqlClient.sni" Version="4.6.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<!-- For publish --><!--
<ItemGroup>
<None Include="$(USERPROFILE)\.nuget\packages\\microsoft.data.sqlclient\1.0.19249.1\runtimes\win\lib\netcoreapp2.1\microsoft.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
--><!-- For local debug --><!--
<Target Name="CopyToBin" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE)\.nuget\packages\microsoft.data.sqlclient\1.0.19249.1\runtimes\win\lib\netcoreapp2.1\microsoft.Data.SqlClient.dll" DestinationFolder="$(OutputPath)\bin" />
</Target>-->
<ItemGroup>
<None Include="$(USERPROFILE)\.nuget\packages\\system.data.sqlclient\4.7.0\runtimes\win\lib\netcoreapp2.1\system.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Target Name="CopyToBin" BeforeTargets="Build">
<Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.data.sqlclient\4.7.0\runtimes\win\lib\netcoreapp2.1\system.Data.SqlClient.dll" DestinationFolder="$(OutputPath)\bin" />
</Target>
</Project>
Please make sure your azure function meet these criteria in this link.
And here is a workaround provided by others, add the following to your .csproj:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)bin\function.deps.json" />
</Target>
<Target Name="PostPublish" BeforeTargets="Publish">
<Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)bin\function.deps.json" />
</Target>
It worked for me by adding below code in csproj file :
<Target Name="PostPublish" BeforeTargets="Publish">
<Exec Command="move $(PublishDir)\runtimes $(PublishDir)\bin" />
</Target>
This line should be taking care of that:
<Exec Command="move $(PublishDir)\runtimes $(PublishDir)\bin" />
reference : github
I would like to run Azure Function v1 with .Net461/.Net472 for testing NotificationHub package. However, there is exception when executing below code:
await _hub.CreateOrUpdateRegistrationAsync(registration);
Error is :
Exception while executing function: PushRegister. Microsoft.Azure.NotificationHubs: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=XXX' or one of its dependencies. The system cannot find the file specified.
I tried to downgrade to 10.0.3 then had error like
Microsoft.Azure.NotificationHubs: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0 ...
Below is the XXX.csproj file for reference:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AzureFunctionsVersion>v1</AzureFunctionsVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.KeyVault" Version="3.0.3" />
<PackageReference Include="Microsoft.Azure.NotificationHubs" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.3.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.29" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\YYY\YYY.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Most of the Nuget libraries have the dependency on Newtonsoft package, even the Microsoft.NET.Sdk.Functions has a dependency on it but it is of older version.
You cannot use any other Nuget Packages that have a dependency on Newtonsoft.Json version which is higher than the function runtime dependent version.
When you try to install a NuGet which has the dependency on a higher version of Newtsonsoft package, you simply cannot install it. The only solution is to use an older version of that library that you need.
I have also written a blog on this and on github this is already an open issue
https://medium.com/#hharan618/common-issues-while-development-of-azure-functions-76b08299af58
We have an Azure function app. Runtime version is 2. Occasionally this command fails on our build server (Jenkins running on Windows Server):
dotnet publish C:\temp\OurFunctionApp.csproj -c Release -o C:\temp\output
The error:
C:\Users\user1.nuget\packages\microsoft.azure.webjobs.script.extensionsmetadatagenerator\1.0.1\build\Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator.targets(20,5): error : Metadata generation failed. [C:\temp\OurFunctionApp.csproj]
When I run this command from command line it always works fine.
We don't have Visual Studio installed on our build server.
How to diagnose and fix this error?
.csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.8.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="3.0.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.24" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Project1\Project1.csproj" />
<ProjectReference Include="..\Project2\Project2.csproj" />
<ProjectReference Include="..\Project3\Project3.csproj" />
<ProjectReference Include="..\Project4\Project4.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="ourlist.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
I have the same issue with Net Framework 4.7.
To solve the problem you should update Microsoft.NET.Sdk.Functions nuget package.
In order to avoid the same issue, i have created a Windows accounts (Admin) by DevOps Agent.
The goal of that is to have for each account it's own folder for nugets. (No more // issues on the same folder)
C:\Users\Agent1.nuget
C:\Users\Agent2.nuget
...
Since i have change all Windows service with the new windows account i have no more errors in my builds ;) (need to restart the Agent Windows Service)
After sometime I just deleted and recreate the application. That worked to me
My problem was that I updated Microsoft.NET.Sdk.Functions to version 3+ while I still had a version 2 function. I installed and target v1.0.37 and that resolved the problem
Adding the following to the csproj file:
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
is what fixed it for me.
We currently have deployed a V1 Azure Function and are looking to upgrade this to V2[preview]. However I can't see any way to target .NET Framework 4.6.1 at the moment, only .NET Core when creating a v2 function.
Is it possible use .NET Framework in Azure Function v2?
The Function Runtime in v2 only runs on .NET Core 2.0, so there is no way to target .NET Framework 4.6.1.
Using Visual Studio 2017 Preview 2, I was able to create a 4.61 Azure Functions Library.
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
My full csproj
PLEASE NOTE (future readers) this is subject to change as time goes by and the "preview" becomes integrated into the "real" VS2017.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.1.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.0.0-beta1" />
<PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.1.0-beta1" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha3" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.2" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="Unity" Version="4.0.1" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
<Reference Include="System.Web" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>