"dotnet-ef does not exist" in .net core heroku application - postgresql

I am using jincod's Heroku .NET Core Buildpack to deploy my Core 3.1 MVC application to heroku.
Currently i am trying to apply EF migrations to postgre DB (using Npgsql) by executing command on publish:
<Target Name="PrePublishTarget" AfterTargets="Publish">
<Exec Command="dotnet tool install --global dotnet-ef" />
<Exec Command="dotnet ef database update" />
</Target>
Build fails with these messages:
You can invoke the tool using the following command: dotnet-ef
Tool 'dotnet-ef' (version '3.1.3') was successfully installed.
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.
/tmp/build_35cf57c00fbf62634ac8d644c6e8f4f7/BugTracker.csproj(38,5): error MSB3073: The command "dotnet ef database update" exited with code 1.
! Push rejected, failed to compile ASP.NET Core app.
! Push failed
I explicitly install dotnet-ef, but for some reason it cannot find it?

You need to add "dotnet-tools.json". More info here https://github.com/jincod/dotnetcore-buildpack/pull/104

Related

How To add new webapi project using powershell with specified version

when I used this command in powershell
dotnet new webapi -n NewCatalog
it creat a webapi project base on default version in my pc 2.2
I install .netcore 5 and try to use this command
dotnet new webapi -n NewCatalog --sdk-version 5.0.15 --force
But I fail
Invalid input switch:
--sdk-version
5.0.15
So
How To add new webapi project using powershell with specified version
This command below can work for you to create a project with a specific .NET version.
dotnet new webapi -f net5.0 -n NewCatalog

How to create Entity Framework Migration script from Azure Build Pipe Line?

I'm trying to create an Entity Framework Migration script from my Azure Build Pipe Line.
I have the following two steps. The first step installs version 3.0.0 of dotnet-ef (I'm using .NET Core 3.0). The second step tries to generate the script which is failing and I can't work out why. It seems to work when the Agent Specification is set to "windows-2019" but not "ubuntu-18.04". Does anyone know why this may be the case?
STEP 1
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.158.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
/usr/bin/dotnet tool install --global dotnet-ef --version 3.0.0
Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.
You can invoke the tool using the following command: dotnet-ef
Tool 'dotnet-ef' (version '3.0.0') was successfully installed.
Finishing: dotnet-ef tool install
STEP 2
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.158.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
/usr/bin/dotnet ef migrations script --idempotent --project /home/vsts/work/1/s/blah1.csproj --startup-project /home/vsts/work/1/s/blah2.csproj --output /home/vsts/work/1/a/migrations/BlahContext.sql --context BlahContext
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.
##[error]Error: The process '/usr/bin/dotnet' failed with exit code 1
##[error]Dotnet command failed with non-zero exit code on the following projects :
Finishing: Generate RnhContext Migration Scripts
How to create Entity Framework Migration script from Azure Build Pipe Line?
I could reproduce this issue on agent ubuntu-18.04 with command line task.
Since I am not familiar with the dotnet ef migration script, I use the command line dotnet ef instead. Now, I got the same issue:
After a period of investigation, I found I need add a line to your shell's configuration before I execute the command dotnet ef:
export PATH="$PATH:$HOME/.dotnet/tools/"
So, my command line looks like:
As test, it works fine on the agent ubuntu-18.04:
Check the related ticket for some more details.
Hope this helps.

How do I ensure correct DotNet Core gets included in the build?

I am trying to deploy a .netcore 2.1.5 api to Windows 2012 Server R2
Currently my published api site gives the following error when I navigate to it
HTTP Error 502.5 - Process Failure
Common causes of this issue:
The application process failed to start
The application process started but then stopped
The application process started but failed to listen on the configured port
Troubleshooting steps:
Check the system event log for error messages
Enable logging the application process' stdout messages
Attach a debugger to the application process and inspect
For more information visit: https://go.microsoft.com/fwlink/?LinkID=808681
In the event log I can see
Event 1000, IIS AspNetCore Module
Application 'MACHINE/WEBROOT/APPHOST/MYSITE.COM.AU/MYAPINAME' with physical root 'C:\WebSites\MYSITE.COM.AU\MyApps\MYAPINAME\' failed to start process
commandline '.\dotnet .\mydllname.dll', ErrorCode='0x80004005 : 80008083
From this question
I see that I can include
<PublishWithAspNetCoreTargetManifest>False</PublishWithAspNetCoreTargetManifest>
In the publish profile If I want to ensure the correct version of DotNetCore gets installed on the host computer.
But how do I set that up if I want to use Azure Devops?
I tried checking Publish Web Projects in the Publish task
but I then get an error
No web project was found in the repository. Web projects are identified by
presence of either a web.config file or wwwroot folder in the directory.
Project file(s) matching the specified pattern were not found.
The dependencies include
Microsoft.AspNetCore.App 2.1.5
but I don't see a coresponding dll deployed.
I tried installing dotnet-runtime-2.1.5 on the computer, downloaded from
the installer site
[Update]
I noticed the logs folder was missing so I created it manually
[Update]
I added the task suggested by Eriawan
The YAML is
steps:
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core sdk 2.1.5'
inputs:
version: 2.1.5
I get in the log
2018-10-29T08:29:05.4839748Z ##[section]Starting: Use .NET Core sdk 2.1.5
2018-10-29T08:29:05.4843909Z ==============================================================================
2018-10-29T08:29:05.4843981Z Task : .NET Core Tool Installer
2018-10-29T08:29:05.4844041Z Description : Acquires a specific version of .NET Core from internet or the tools cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks.
2018-10-29T08:29:05.4844089Z Version : 0.1.16
2018-10-29T08:29:05.4844134Z Author : Microsoft Corporation
2018-10-29T08:29:05.4844192Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=853651)
2018-10-29T08:29:05.4844234Z ==============================================================================
2018-10-29T08:29:05.9812262Z Tool to install: .NET Core sdk version 2.1.5.
2018-10-29T08:29:05.9825645Z Checking if a cached copy exists for this version...
2018-10-29T08:29:05.9830151Z Cache does not contains this particular .NET Core. Will be downloaded and installed.
2018-10-29T08:29:05.9833458Z Detected platform (Primary): win-x64
2018-10-29T08:29:05.9833723Z Getting URL to download .NET Core sdk version: 2.1.5.
2018-10-29T08:29:06.5248134Z Could not fetch download information for version 2.1.5. Please check if the version specified is correct. You can refer the link for supported versions => https://github.com/dotnet/core/blob/master/release-notes/releases.json. Falling back to creating convention based URL.
2018-10-29T08:29:06.5481883Z [command]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& 'D:\a\_tasks\DotNetCoreInstaller_b0ce7256-7898-45d3-9cb5-176b752bfea6\0.1.16\externals\install-dotnet.ps1' -Version 2.1.5 -DryRun"
2018-10-29T08:29:07.6386710Z dotnet-install: Payload URLs:
2018-10-29T08:29:07.6387117Z dotnet-install: Primary - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T08:29:07.6387245Z dotnet-install: Legacy - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T08:29:07.6387445Z dotnet-install: Repeatable invocation: .\install-dotnet.ps1 -Version 2.1.5 -Channel LTS -Architecture x64 -InstallDir <auto>
2018-10-29T08:29:07.6451802Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T08:29:08.8792388Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip Error: {}
2018-10-29T08:29:08.8807163Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T08:29:09.5450400Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip Error: {}
2018-10-29T08:29:09.5453128Z ##[error]Failed to download package for installation
2018-10-29T08:29:09.5551776Z ##[section]Finishing: Use .NET Core sdk 2.1.5
The designer shows
The csproj is
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<ApplicationIcon />
<OutputType>Exe</OutputType>
<StartupObject />
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\netcoreapp2.1\trackApi.xml</DocumentationFile>
<DefineConstants>TRACE;DEBUG;NETCOREAPP2_1</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netcoreapp2.1\trackApi.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Folder Include="logs\" />
<Folder Include="Views\Account\" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.5" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<Content Update="appsettings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
[Update]
problems in build pipeline
[Update]
I created a new pipeline using YAML
pool:
vmImage: 'VS2017-Win2016'
variables:
buildConfiguration: 'Debug'
steps:
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core sdk 2.1.5'
inputs:
version: 2.1.5
- task: DotNetCoreCLI#2
displayName: Restore
inputs:
command: restore
projects: '**/Api*.csproj'
However I still get an error
018-10-29T09:36:13.7155347Z ##[section]Starting: Use .NET Core sdk 2.1.5
2018-10-29T09:36:13.7158688Z ==============================================================================
2018-10-29T09:36:13.7158742Z Task : .NET Core Tool Installer
2018-10-29T09:36:13.7158774Z Description : Acquires a specific version of .NET Core from internet or the tools cache and adds it to the PATH. Use this task to change the version of .NET Core used in subsequent tasks.
2018-10-29T09:36:13.7158842Z Version : 0.1.16
2018-10-29T09:36:13.7158878Z Author : Microsoft Corporation
2018-10-29T09:36:13.7158926Z Help : [More Information](https://go.microsoft.com/fwlink/?linkid=853651)
2018-10-29T09:36:13.7158958Z ==============================================================================
2018-10-29T09:36:14.1220877Z Tool to install: .NET Core sdk version 2.1.5.
2018-10-29T09:36:14.1231419Z Checking if a cached copy exists for this version...
2018-10-29T09:36:14.1238258Z Cache does not contains this particular .NET Core. Will be downloaded and installed.
2018-10-29T09:36:14.1240864Z Detected platform (Primary): win-x64
2018-10-29T09:36:14.1240993Z Getting URL to download .NET Core sdk version: 2.1.5.
2018-10-29T09:36:14.5706519Z Could not fetch download information for version 2.1.5. Please check if the version specified is correct. You can refer the link for supported versions => https://github.com/dotnet/core/blob/master/release-notes/releases.json. Falling back to creating convention based URL.
2018-10-29T09:36:14.5957734Z [command]C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "& 'D:\a\_tasks\DotNetCoreInstaller_b0ce7256-7898-45d3-9cb5-176b752bfea6\0.1.16\externals\install-dotnet.ps1' -Version 2.1.5 -DryRun"
2018-10-29T09:36:15.3109409Z dotnet-install: Payload URLs:
2018-10-29T09:36:15.3109790Z dotnet-install: Primary - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T09:36:15.3109942Z dotnet-install: Legacy - https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T09:36:15.3110089Z dotnet-install: Repeatable invocation: .\install-dotnet.ps1 -Version 2.1.5 -Channel LTS -Architecture x64 -InstallDir <auto>
2018-10-29T09:36:15.3188675Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip
2018-10-29T09:36:16.5236693Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-sdk-2.1.5-win-x64.zip Error: {}
2018-10-29T09:36:16.5256084Z Downloading: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip
2018-10-29T09:36:17.2185860Z ##[warning]Could not download installation package from this URL: https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip Error: {}
2018-10-29T09:36:17.2189408Z ##[error]Failed to download package for installation
2018-10-29T09:36:17.2271136Z ##[section]Finishing: Use .NET Core sdk 2.1.5
The url https://dotnetcli.azureedge.net/dotnet/Sdk/2.1.5/dotnet-dev-win-x64.2.1.5.zip shows an error
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>BlobNotFound</Code>
<Message>
The specified blob does not exist. RequestId:7447502f-301e-00a8-516d-6f7cde000000 Time:2018-10-29T09:57:58.4200303Z
</Message>
</Error>
[Update]
Eriawan has the answer.
I needed to use a YAML pipeline and get the version here.
In order to control the build to use specific version of .NET Core runtime, you must tell the build agent to install the .NET Core SDK to use and also specify the SDK version to install before building your code.
If you use YAML on your Azure DevOps Pipelines build, you could run this task: DotNetCoreInstaller#0 and set the version of to 2.1.403 .
The task must be run before any tasks, preferably the first task to run.
For example:
- task: DotNetCoreInstaller#0
inputs:
version: '2.1.403'
If you're using the build definition designer, add the ".NET Core Tool Installer" task and specify the version that you want to use from there.
Please consult .NET Core build sample on MSFT docs:
https://learn.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=vsts&tabs=yaml#build-environment
UPDATE 1:
OK, I have seen your build error. Looks like the .NET Core installer task has wrong URL address for .NET Core SDK of 2.1.403.
You can use pure YAML instead. I will file a bug on the .NET Core installer task repo. In the meantime, please use a full YAML.
I already have one working YAML file, a sample of this is available on my own repo.
For example:
https://github.com/RXCommunica/rx-azuredevops-rest/blob/master/azuredevopsrest-ci-vs2017.yml
UPDATE 2:
I have added comments for your YAML. The .NET Core tool version on your YAML is incorrect. Update/change your yaml from the original:
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core sdk 2.1.5'
inputs:
version: 2.1.5
to:
- task: DotNetCoreInstaller#0
displayName: 'Use .NET Core sdk 2.1.5'
inputs:
version: 2.1.403
This is important, because version of .NET Core runtime is not equal to the version of the actual SDK tool version.
Please consult this doc for the tool version and the related runtime list of .NET Core 2.1:
https://www.microsoft.com/net/download/dotnet-core/2.1

How to avoid Edeliver deployment error: "vm.args: No such file or directory"?

Context
We are trying to use edeliver to deploy a "Hot Upgrade" of a Phoenix Web Application to a remote Virtual Machine instance.
Our aim is to build an "upgrade" version of the app each time so that the app can be "hot" upgraded in production without any down-time.
We have succeeded in doing this "hot upgrade" on a "Hello World" phoenix app:
https://github.com/nelsonic/hello_world_edeliver which is automatically deployed from Travis-CI when the build passes. see: https://travis-ci.org/nelsonic/hello_world_edeliver/builds/259965752#L1752
So, in theory this technique should work for our "real" app.
Attempting to Deploy a "Real" Phoenix App using Edeliver
Ran the following command (to build the upgrade):
mix edeliver build upgrade --auto-version=git-revision --from=$(git rev-parse HEAD~) --to=$(git rev-parse HEAD) --verbose
i.e. "build the upgrade from the previous git revision to the current one"
So far, so good. "Release successfully built!"
Error: vm.args: No such file or directory
When we attempt to deploy the upgrade:
mix edeliver deploy upgrade to production --version=1.0.3+86d55eb --verbose
cat: /home/hladmin/healthlocker/releases/1.0.3+86d55eb/vm.args: No such file or directory
Note: we have a little bash script that reads the latest upgrade version available in .deliver/releases and deploys that see: version.sh
Question:
Is there a way to ignore the absence of the vm.args file and continue the deployment?
Or if the file is required to complete the deployment, is there some documentation on how to create the file?
Note: we have read the distillery "Runtime Configuration" docs: https://github.com/bitwalker/distillery/blob/master/docs/Runtime%20Configuration.md and are sadly none-the-wiser ...
Additional Info
Environment
Localhost: Mac running Elixir 1.4.2
Build Host: Ubuntu 16.04.2 LTS running Elixir 1.4.5
mix.exs file: https://github.com/healthlocker/healthlocker/blob/continuous-delivery/mix.exs
edeliver version: 1.4.4
Build tool: distillery version: 1.4.0
Umbrella project: yes.
This question was also asked on: https://github.com/edeliver/edeliver/issues/234
As mentioned by others, the vm.args file is necessary for BEAM to run the release. A default file is created by distillery during the release build process and should be located in releases/<version>/vm.args. From your log output it looks like expected directory is being checked.
Can you show us the contents of /home/hladmin/healthlocker/releases/?
Can you confirm that the default vm.args file is being created when building the release and extracting it (outside of the upgrade process)?
You also asked:
Or if the file is required to complete the deployment, is there some documentation on how to create the file?
If diagnosing the problem with the default vm.args file doesn't get you anywhere, you can also write your own file and configure distillery to use that file instead of the default. The details for this are in the distillery configuration docs. In short,
add the vm_args setting to your distillery config, which should be at rel/config.exs(relative to your project root), for example:
environment :prod do
set vm_args: "<path>/vm.args"
[...]
end

Running "ngen install EntityFramework.dll" fails with error 0x800706BE and 0x80131F06

As advised by the Entity Framework Team I've tried to create a native image of EntityFramework.dll with this command:
ngen install packages\EntityFramework.6.1.0-beta1\lib\net40\EntityFramework.dll
this results in the error 0x80131F06 (no native image for mscorlib.dll). When I now try to run ngen install mscorlib.dll I get the error 0x800706BE (RPC_S_CALL_FAILED - The remote procedure call failed).
I already used sfc /scannow and it reports no broken files.
Any ideas what is wrong here?
I fixed the issue myself. It is caused by the enabled DeveloperMode which was set by Redgates .NET Reflector VisualStudio Addon. Disabling it with this entry in the machine.config fixed it:
<runtime>
<developmentMode developerInstallation="false"/>
</runtime>
Now I have a native Image for mscorlib and I can ngen EF.