2

In visual studio we can create an empty asp.net core project. Do we have anything like that in visual studio code, or we only have to create an asp.net core MVC with this command : dotnet new mvc -o MyProjectName ?

3 Answers 3

3

In this doc about dotnet new command, it lists the templates that come pre-installed with the .NET SDK.

And we can run dotnet new --list or dotnet new -l to see a list of all installed templates.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

I got the answer. We have to use : dotnet new web instead of dotnet new mvc. For more information we can write dotnet new in the command. This Show us more CLI and help to know how to create projects in visual studio code.

Comments

0

Here is an alternative you can try. I know of no advantage for doing this except for the fun of it. One possible advantage is that we can customize anything during this process if we know what we need to do for the customization.

Create a folder for the project, of course. In it create a csproj file with the following; change the TargetFramework as appropriate.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

</Project>

Create an appsettings.json file with the following (note the AllowedHosts).

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

Create an appsettings.Development.json file with the following (note there is no AllowedHosts). VS Code however will not allow use of the name appsettings.Development.json. A workaround is to (in VS Code) copy and paste the appsettings.jsonfile then rename that. Be sure to remove the AllowedHosts.

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  }
}

Outside of VS Code, create a Properties folder (VS Code says that Properties is not a valid folder name). Add a launchSettings.json file to the folder with the following. The ports can be customized.

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:28210",
      "sslPort": 44341
    }
  },
  "profiles": {
    "AspNetCoreEmpty": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7126;http://localhost:5126",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

Create a Program.cs with the following.

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

app.MapGet("/", () => "Hello World!");

app.Run();

Go to the project directory in a terminal window and issue:

dotnet build

It should build. The project will essentially be the same as if it was built using dotnet new web.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.