How To add new webapi project using powershell with specified version - powershell

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

Related

Cannot import jdl file using jhipster

I'm new to jhipster. I am on jhipster v7.8.1, i can generate an app using the cli questions but when i try importing a jdl file i got the following error:
**ERROR! Class constructor GAstVisitor cannot be invoked without 'new'
TypeError: Class constructor GAstVisitor cannot be invoked without 'new'
at new DslMethodsCollectorVisitor
This occurs due to a recent bug in the one of JHipster libraries. As a temporary solution you can go to the JHipster installed location and find it's package.json file and override the package causing this error as follows. Then run npm install again.
"overrides":{
"chevrotain#10.1.2": {
"#chevrotain/gast": "10.1.2"
}
}
This will prevent the JHipster using latest package of that.
I experienced the same error and managed to get the JDL file to run by using version 7.8.1
I followed the following steps to get this done;
uninstall the current version of jhipster that is causing issues for
my case this was 7.9.2 . use this command npm uninstall -g
generator-jhipster
Install version 7.8.1 using this command npm
install -g generator-jhipster#7.8.1
Attempt to run your JDL using
this command jhipster jdl jhipster-jdl.jdl
At this stage, your JDL
will be able to run

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

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

How to Enable Intellisense in VS Code + Ionide?

I've created an F# (script) app via the dotnet cli using the following outlined steps. However, when I open the app/project in VS Code with Ionide, intellisense is inactive. How can I resolve this?
To create the app/project, I:
Created an app directory
Ran dotnet new tool-manifest and dotnet tool install paket and dotnet paket restore
Ran dotnet paket init
Modified paket.dependencies
Opened "project" in VS Code with Ionide
paket.dependencies (Note: I removed framework restrictions)
source https://api.nuget.org/v3/index.json
storage: packages
nuget FSharp.Data
Script:
#r "./packages/FSharp.Core/lib/netstandard2.0/FSharp.Core.dll"
#r "./packages/FSharp.Data/lib/netstandard2.0/FSharp.Data.dll"
open System
open FSharp.Data
type research = CsvProvider<"./path/to/file", HasHeaders=true, PreferOptionals=true>
let data = research.GetSample()

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.

Dotnet restore not working

dotnet Version: 1.1.0 (global.json)
NuGet Version : 4.4.1.4656
VS2017 v15.5.2 (as Administrator)
.NET Core 1.1
The solution I am trying to build
Update I:
I just changed the project to run under target framework .NET Core v2.0 & sdk version 2.1.3 and I only get these kind of errors:
Severity Code Description Project File Line Suppression State
Error NU1202 Package Microsoft.Extensions.FileProviders.Physical 1.1.0
is not compatible with netcoreapp2.0 (.NETCoreApp,Version=v2.0).
Package Microsoft.Extensions.FileProviders.Physical 1.1.0 does not
support any target
frameworks. AspNetCoreExample C:\Users\Admin\Source\Repos\Examples\src\AspNetCoreExample\AspNetCoreExample.csproj 1
Update II:
While the following solves the current issue, i am not sure if it solves the root cause for this issue.
Delete the global nuget.config file %AppData%/Nuget/Nuget.config.
I fixed this issue by doing the following:
I migrated the project to .net core 2.0 and changed the global.json to point to sdk 2.1.3.
Removed all references in AspNetCoreExample manually and added the latest version for all of them.
Issues with target framework 1.1
When doing a restore from the solution in VS 2017:
When doing the restore from cmd (dotnet restore)
Running dotnet restore in Package Manager Console
NuGet.targets(103,5): error : Access to the path 'System.Runtime.dll'
is denied
.NET Core SDKs installed:
.NET Host
Now when opening the solution I get:
Comparing the log entries you pasted to their AppVeyor build,
https://ci.appveyor.com/project/Autofac/examples
Your machine's NuGet configuration seems to be broken. Analyze that and fix the issues.
You should add this code to your .csproj file
<RuntimeFramework>2.0.3</RuntimeFramework>
This worked for me.