Why am I getting duplicate errors in my obj/Release/net6.0 folder after building and deploying Azure function in VS Code - azure

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

Related

ASP .NET Core : Directory.EnumerateFiles and IIS hosting

When I publish my ASP .NET Core (v.2.2) web application on a IIS-server it throws an exception on this line:
Directory.EnumerateFiles(_environment.ContentRootPath + #"/Pages/API")
The exception:
An unhandled exception has occurred while executing the request.
Could not find a part of the path 'C:\Release\MySite\Pages\API'.
System.IO.DirectoryNotFoundException at
System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String
path, Boolean ignoreNotFound)
When I look inside the published folder there is no API folder, but should it not be inside of my website dll? Or can I not use relative or absolute paths to find files in my web project when I publish it on ISS?
Note: The pages in folder API have Build Action : content, and the code works without problem in development (with IIS-express).
For asp.net core, it will precompile views while publishing into Project.Views.dll. For Directory.EnumerateFiles, it only lists the real exist files in the disk.
For a solution, try to modify your project.csproj to add <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>.
Full
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
</ItemGroup>
</Project>

include c/c++ unmanaged code dll, consumed using dllimport, in azure functions publish process

How does one include in a c/c++ unmanaged code dll, consumed using v2 .net core compatible DllImportAttribute statements, in azure functions publish process?
I've confirmed it works in cloud deployment by manually copying, via azure storage explorer, to functions app storage account | file shares | | site/wwwroot/bin folder.
Issue is now I haven't been able to find way to have it included in vs17 | | Publish process.
Tried placing dll in \bin\$(Configuration)\netcoreapp2.1\bin folder before executing vs17 | | Publish but doesn't result in it being picked up.
In VS, right click on your Function project and Edit <FunctionProjectName>.csproj. Add items below to copy dlls we need when publishing or debugging locally.
<!-- For publish -->
<ItemGroup>
<None Include=" relative or absolute path to your dll, which is not in your project">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- If you have put dlls under your project root -->
<ItemGroup>
<None Update="YourDllName.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<!-- For local debug -->
<Target Name="CopyToBin" BeforeTargets="Build">
<Copy SourceFiles="relative or absolute path to your dll" DestinationFolder="$(OutputPath)\bin" />
</Target>

Azure function multiple output binding Extensions error

I'm developing an Azure function through the portal,
My function is an HttpTrigger with httpResponse.
I add a TableStorage output binding and install its Extension (everything is fine).
I add a SendGrid output binding and install its Extension (the extension installer give me a message saying "it takes longer than expected" and seems to fail. Afterward, my function is broken.
I tried creating my bindings in reverse order (SendGrid then TableStorage). It now fails on TableStorage installation.
Any way to resolve this issue?
Thanks
It's a known issue that sometimes filesystem for Consumption plans reacts slow, e.g during extension installation with many file I/O operations.
The first suggestion is to delete the extensions and retry.
Stop Function app.
In portal, Platform features> App Service Editor.
Right click on bin folder and extensions.csproj, Delete.
Start Function app.
Delete existing output bindings and add them again to install extensions.
If this doesn't work, try to manually install the extensions.
Stop Function app.
In portal, Platform features> App Service Editor.
Right clik on the blank under WWWROOT, New File extensions.csproj then add content below.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SendGrid" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.2" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.0.*" />
</ItemGroup>
</Project>
Press Ctrl+Shift+C to open console, or click the second button Open Console from the bottom on the sidebar.
Input dotnet build extensions.csproj -o bin --no-incremental --packages D:\home\.nuget and wait for the command to finish.
Start Function app.

CopyAllFilesToSingleFolderForMsdeployDependsOn hook works on local but not when built in TFS

With reference to this article by SamStephens and this by Sayed, I have managed to include additional dependent files during packaging when built LOCALLY using Visual Studio 2012.
The issue starts when I built the codes in TFS. Looking through the logs, it looks like the CopyAllFilesToSingleFolderForMsdeployDependsOn is not hooked on.
CopyAllFilesToSingleFolderForMsdeployDependsOn =
;
;
CopyAllFilesToSingleFolderForPackageDependsOn =
;
;
So I have a Deployment.csproj with a CreatePackage.targets file and in this target file, it would build the web application project. The following is the snippet of the file which I combine what I learned from both the articles stated earlier.
<!-- Create Web Deploy package for local build. -->
<Target Name="WebPackage" Condition="'$(TfsBuild)' == ''">
<!-- MSBuild the project. -->
<MSBuild Projects="..\webapplication.csproj"
Targets="Package"
Properties="
Platform=$(Platform);
VisualStudioVersion=$(VisualStudioVersion);
Configuration=$(Configuration);
WebPublishMethod=Package;
ExcludeApp_Data=false;
DeployOnBuild=true;
DeployTarget=Package;
PackageAsSingleFile=true;
PackageLocation=$(PackageOutputDirectory);
PublishProfile=$(MSBuildThisFileFullPath);
ExcludeFoldersFromDeployment=Scripts;
ExcludeFilesFromDeployment=parameters.xml;">
</MSBuild>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForMsdeployDependsOn>
DefineAssemblies;
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForMsdeployDependsOn);
</CopyAllFilesToSingleFolderForMsdeployDependsOn>
<AssemblySource Condition="'$(TfsBuild)' == ''">$(SolutionDir)\ProjectA\bin\$(Configuration)\ProjectA.dll</AssemblySource>
<AssemblySource Condition="'$(TfsBuild)' == 'true'">$(OutputDirectory)ProjectA.dll</AssemblySource>
<Target Name="DefineAssemblies">
<ItemGroup>
<FilesToInclude Include="$(AssemblySource)">
<Dir>lib</Dir>
</FilesToInclude >
</ItemGroup>
</Target>
<Target Name="CustomCollectFiles">
<ItemGroup>
<FilesForPackagingFromProject Include="#(FilesToInclude )">
<DestinationRelativePath>%(FilesToInclude.Dir)\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
So the question is: Why is this working nicely locally in VS2012 and not in the TFS build?
I've been stuck in this for two days now so I would really appreciate any help.

TFS Deployment to Azure Error: cannot find ClientPerfCountersInstaller.exe

I configured our implementation to use the Azure Caching provider to maintain session state between all cloud instances like described here:
http://msdn.microsoft.com/en-us/library/windowsazure/gg185668.aspx
This created a new startup task on my csdef file that always fails with this error:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.0\Microsoft.WindowsAzure.targets (987): CloudServices64 : Cannot find file named 'approot\bin\Microsoft.WindowsAzure.Caching\ClientPerfCountersInstaller.exe' for startup task Microsoft.WindowsAzure.Caching\ClientPerfCountersInstaller.exe install of role MyRole.Web.
The .exe in the nuget package and in the main folder is included in the source control that TFS uses for the deployment.
I found this previous question that addresses this same issue:
Azure Deployment Error: cannot find ClientPerfCountersInstaller.exe
But the accepted answer states to just delete the startup task that installs the .exe needed for the caching to take place.
Make sure the .exe is marked as CopyAlways so that it is copied to your \bin directory.
To do so, right click on the .exe in Visual Studio and select properties. Make sure it looks like this:
I had a similar issue with a dedicate cache worker role, but in my case the Microsoft.WindowsAzure.Caching folder never showed up in VisualStudio. In the end, I had to open the .csproj file for the worker role project and this:
<None Include="Microsoft.WindowsAzure.Caching\ClientPerfCountersInstaller.exe.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Microsoft.WindowsAzure.Caching\ClientPerfCountersInstaller.exe">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Microsoft.WindowsAzure.Caching\PerformanceCounters.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
I put that within the same <ItemGroup> tag as the app.config file, and now it's deploying as it should.

Resources