Unable to publish Azure function app v3 C# with .net 5 - c#

I am unable to publish my .net function app. I am using the below configuration and settings:
.net 5 SDK Version: 5.0.300
Microsoft.Azure.Functions.Worker 1.2.0
Microsoft.Azure.Functions.Worker.Core 1.1.0
Getting below error:
Metadata generation failed. Exit code: '-532462766' Error: 'Error generating extension metadata: System.IO.DirectoryNotFoundException: The path PATH\bin\Release\net5.0\publish\bin does not exist. Unable to generate Azure Functions extensions metadata file.

The problem lies with the .targets file of Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator, it sets the _FunctionsExtensionsDir to the publish target directory + 'bin'
So if you publish to project-path\bin\release\net5.0\publish, it's looking for published output in project-path\bin\release\net5.0\publish\bin - you can prove this by doing a replace all in the .targets file replacing ')bin' with ')' and watching it run as expected.
A quick and dirty solution is to build with the -o flag set to where the metadata generator will expect the output to be, e.g.
dotnet build yourproject.csproj --framework net5.0 -c release -o c:/temp/output/bin -v d
dotnet publish yourproject.csproj --framework net5.0 -c release -o c:/temp/output -v d
I'm currently looking into a less hacky way of achieving this, and will post if/when I figure it out.

This looks like a bug in Visual Studio 2019.
Suggestion:
Record your current version, you can raise a support ticket to confirm with the official.
Upgrade your vs2019 to the latest version and try to publish again.

Related

Azure devops private nuget takes a long time to find package

We are using Azure DevOps pipelines. We have a step that publishes the our private nuget package to the Azure Artifacts. However, the build breaks at other steps because the nuget package (that was published on previous steps) is not found. The strange thing is that after the package is published, I can see it in the package-manager console or on Visual Studio and even in the Artifacts in Azure DevOps. But for some reason, the pipeline doesn't find the package. After 30-50min, I re-run the pipeline and then it finds the package.
What could be happening to take so long time for the pipeline to find the my package?
Edit 1:
This is my yaml for the step with error
- script: |
pwd && ls -la
dotnet restore "$(solution_path)" $(nuget_args)
dotnet publish -c Release -o $(System.DefaultWorkingDirectory)/bin "$(main_project_path)"
mkdir artifact
cp -r $(System.DefaultWorkingDirectory)/bin artifact/bin
displayName: Build Application
The error is:
/data/vstsagent/user/389/s/src/MyProject.csproj
: error NU1102: Unable to find package MyPackage with
version (>= 2.1.0) [/data/vstsagent/user/389/s/src/MySolution.sln]
/data/vstsagent/user/389/s/src/MyProject.csproj
: error NU1102: - Found 28 version(s) in MyPrivateRepository [ Nearest
version: 2.1.0-preview.6 ]
[/data/vstsagent/user/389/s/src/MySolution.sln]
It is not clear what feed is used by dotnet restore command.
Confirm that you have configured your custom nuget feed in nuget.config and using it.
Try adding "--verbose" switch in dotnet restore command and check if your feed is used for restoring packages.
Use the --no-cache option so dotnet restore doesn't use the local cache.

zsh: command not found: dotnet-ef

I am using asp.net core 2.1 with visual studio code or rider in mac. I already have a 2.1 sdk install on mac, while using the below command
dotnet-ef database update --project XXXX.XXXX
I get an exception as
zsh: command not found: dotnet-ef
Using the command
dotnet tool install --global dotnet-ef
getting an exception as Tool 'dotnet-ef' is already installed.
Then using this command dotnet tool restore
error NU3037: Package 'dotnet-ef 3.1.1' from source 'https://api.nuget.org/v3/index.json': The repository countersignature validity period has expired.
Package "dotnet-ef" failed to restore, due to Microsoft.DotNet.ToolPackage.ToolPackageException: The tool package could not be restored.
For mac I need to export the below path
export PATH="$PATH:$HOME/.dotnet/tools/"
Yes, give an example of the error:
$ dotnet ef
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
The second and third refer to dotnet trying to find a dotnet-ef command but it cannot find it. As the third point said, dotnet-ef is not on your way.
This is what the documentation says:
Global tools can be installed in the default directory or in a specific location. The default directory is:
OS Path
Linux/macOS $HOME/.dotnet/tools
Windows %USERPROFILE%\.dotnet\tools
So, you should add $HOME/.dotnet/tools/ to your $PATH.
For Linux and macOS, add a line to the shell configuration:
bash/ zsh:
export PATH="$PATH:$HOME/.dotnet/tools/"
When you start a new shell/terminal (or next time you log in) dotnet ef should work.
For Windows:
You need to add %USERPROFILE%.dotnet\tools to PATH.
I am using asp.net core 6.0
zhengguo#macdeMac-min % echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
The PATH has already exist ~/.dotnet/tools
When I use dotnet aspnet-codegenerator, it works. dotnet-aspnet-codegenerator not work.

Azure Pipeline: dotnet publish fails - assets.json doesn't have a target for '.NETCoreApp,Version=v3.1/win-x64'

I have a .NetCore 3.1 commandline app. When buidling locally and publishing, it works completely fine using below commandline
dotnet publish -c dev -r win-x64 --self-contained true
In the Azure pipeline - I had to do the dotnet restore before doing a publish using the above command. Whilst publishing I had to add extra param --no-restore, as per Microsoft's recommendation here as I have private nuget feeds.
dotnet publish -c dev -r win-x64 --self-contained true --no-restore
Most dotnet commands, including build, publish, and test include an
implicit restore step. This will fail against authenticated feeds,
even if you ran a successful dotnet restore in an earlier step,
because the earlier step will have cleaned up the credentials it used.
To fix this issue, add the --no-restore flag to the Arguments textbox.
Now, the publish part of the pipeline has started failing with the error -
C:\Program Files\dotnet\sdk\3.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1047: Assets file 'MyProject\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.1/win-x64'. Ensure that restore has run and that you have included 'netcoreapp3.1' in the TargetFrameworks for your project. You may also need to include 'win-x64' in your project's RuntimeIdentifiers.
Am not using a publish xml, but specifying all the arguments as shown above in the command line. I've checked the csproj has the target framework specified
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;dev;test;pre;prod</Configurations>
</PropertyGroup>
Need any pointers as to what might be going wrong here?
Thanks
Please add RuntimeIdentifier as mentioned in the error message:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Configurations>Debug;Release;dev;test;pre;prod</Configurations>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
Please also check PlatformTarget.
<PlatformTarget>AnyCPU</PlatformTarget>
I guess the local machine has a different OS than the build agent.

using the docfx.console nuget package on linux

At the moment I have a visual studio project and I use the docfx.console nuget package to build the documentation, and everything works fine and as expected... on windows. The point is now I want to make a docker image based on mcr.microsoft.com/dotnet/core/sdk:3.1 which is based on a linux image. And compiling in this docker image running the command:
dotnet publish -c Release -o out
Gives the following error
> [build 9/9] RUN dotnet publish -c Release -o out:
#22 1.080 Microsoft (R) Build Engine version 16.0.450+ga8dc7f1d34 for .NET Core
#22 1.080 Copyright (C) Microsoft Corporation. All rights reserved.
#22 1.080
#22 2.852 Restore completed in 215.94 ms for /app/Documentation/Documentation.csproj.
#22 6.299 Documentation -> /app/Documentation/bin/Release/netcoreapp2.1/Documentation.dll
#22 6.402 /bin/sh: 2: /tmp/tmpbd72ebbe5e6b49c1b3244f1f50c8b57a.exec.cmd: /root/.nuget/packages/docfx.console/2.48.1/build/../tools/docfx.exe: Exec format error
#22 6.407 /root/.nuget/packages/docfx.console/2.48.1/build/docfx.console.targets(57,5): error MSB3073: The command ""/root/.nuget/packages/docfx.console/2.48.1/build/../tools/docfx.exe" "/app/Documentation/docfx.json" -o "" -l "log.txt" --logLevel "Verbose"" exited with code 2. [/app/Documentation/Documentation.csproj]
I already did some prodding around and I believe I have the issue mostly solved. Running file on console.exe shows that this is a PE32 executable (console) Intel 80386 Mono/.Net assembly, for MS Windows. And these kind of files should not be executed on linux using sh but with mono. And indeed running:
mono docfx.exe "/app/Documentation/docfx.json" -o "" -l "log.txt" --logLevel "Verbose"
builds the documentation just fine as expected. At this point of course I have a bunch of workarounds to get the documentation building correctly, just remove docfx.console form the csproj and build it manualy from the command line using a docker command.
But the question is, can I also use the nuget package on linux by changing how the docfx.exe command is run by the nuget package? Or is this only possible by actually fixing this in docfx.console?
p.s. in case it matters, the version of docfx.console that I am using is the most recent one available at the time of writing, namely 2.48.1
But the question is, can I also use the nuget package on linux by changing how the docfx.exe command is run by the nuget package? Or is this only possible by actually fixing this in docfx.console?
Create script docfx that runs docfx.exe using Mono, e.g., like this (assuming docfx.exe is located in /opt/docfx/docfx.exe):
echo '#!/bin/bash\nmono /opt/docfx/docfx.exe $#' > /usr/bin/docfx && chmod +x /usr/bin/docfx
Then, pass MSBuild parameter BuildDocToolPath with path to that script, e.g., like this:
dotnet publish -c Release -o out -p:BuildDocToolPath=/usr/bin/docfx
docfx.console will than use this path to execute DocFX. I think the property BuildDocToolPath isn't documented anywhere, but you can see it in source code.

.NetCore for Mac - Publish to Native Mac App/Binary?

I've been searching for quite some time now, and can't seem to find an answer to this problem. Found only two questions/answers on SO and they still don't answer this question (https://stackoverflow.com/search?q=netcore+publish+mac+app).
I'm working with DotNetCore on Mac, using Visual Studio as the IDE. The app is a Console App, not an ASP.Net app, simple "Hello World" app in C#:
...
Console.Writeline("Hello World");
...
So here's the question... To run the app, I know I can use the "dotnet" command to run it. I'm trying to build/publish the app, as you normally would do in Windows by creating an .exe file, but now on Mac by creating a native binary file.
I have found zero documentation on how to do this, and deploy the application as a self contained app that can run independently without having to call the program using the "dotnet" command. Maybe I'm looking in the wrong places but haven't even found anything on Microsoft's documentation, they all point to documentation for building ASP.Net apps on .NetCore.
Any suggestions?
Found the answer by looking at the "dotnet publish" options:
dotnet publish -c Release --self-contained -r osx.10.13-x64
Where --self-contained includes all required libraries, and -r specifies the runtime target.
$ dotnet publish -c Release --self-contained -a x64
Determining projects to restore...
Restored /Users/walshca/code/temp/MutexThrow/MutexThrow.csproj (in 155 ms).
MutexThrow -> /Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/MutexThrow.dll
MutexThrow -> /Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/publish/
dotnet publish docs
Then I run ./bin/Release/net6.0/osx-x64/publish/MutexThrow
This didn't specify the --output cli arg, so you can see in the build output it defaulted to [project_file_folder]/bin/[configuration]/[framework]/[runtime]/publish/
(In dotnet 6.0 instead of -r runtime target, you can specify --arch x86 and it uses the default RID for your system.)
If your project props sets a different build output, can you find the executable by enumerating files by unix file permissions:
$ gci -r -file | ? UnixMode -match 'x$' | % FullName
/Users/walshca/code/temp/MutexThrow/obj/Release/net6.0/osx-x64/apphost
/Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/MutexThrow
/Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/publish/MutexThrow

Categories

Resources