Run .NET Core App via Console in VS2015 - asp.net

In Visual Studio 2015 Community Edition, I run my .NET Core Web API application via console by choosing [AppName] from running profile options on toolbar (Near Little green triangle, dropdown menu) in my previous project. The default options were IIS Express and [AppName], which runs dotnet restore and dotnet run from command prompt.
After I reinstall Windows 10 and therefore VS2015, When I create a new project, I can no longer see default [AppName] option in the dropdown. It has just one option, which is IISExpress.
How can I enable it again? I've also installed dot net core tools for VS2015.
Thanks.

I have found the solution.
In Solution Explorer > YourProject > Properties > launchSettings.json,
You should add this to the in profiles:
"YourProjectName": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
And then you can change starting option:

Related

Unable to debug WSL2 with VS 2022 - invalid 'cwd' value

I am trying to debug from WSL2 using my VS 2022 IDE in Windows, but I get the following error:
The cwd value does indeed look wrong, but how do I fix it?
I am using .netcore 6.0.101, Ubuntu 20.04.3 and Windows 11.
launchSettings.json:
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "local"
},
"applicationUrl": "https://localhost:56962;http://localhost:56963",
"distributionName": "Ubuntu"
}
}
}
PS C:\Users\me> wsl -l -v
NAME STATE VERSION
* Ubuntu Running 2
docker-desktop Running 2
docker-desktop-data Running 2
This has been fixed in 17.4 Preview 5.
The latest Preview releases are available for download here.
I tried to search some useful information for you, somebody said this is permisson issue. But I this below description is correct.
Currently the extension only support opening projects that are stored in the windows disks (it leverages WSLs automount feature).
Related Post:
Debug Your .NET Core Apps in WSL 2 with Visual Studio
In Visual Studio 2022:
Go to the project properties (right click on the project name in the Solution Explorer, then Properties on the pop up menu).
Then, write in the search bar "working directory" and click on "Open debug launch profiles UI" here you'll find the "Working Directory" setting where you should set the wsl2 path you need.
You have this error because Windows doesn't know about linux path used on WSL.
But you can access your WSL2 directories on Windows using \\wsl$ path.
If your WSL2 machine name is Ubuntu, you need to define cwd value with following path:
\\wsl$\Ubuntu\home\<the_rest_of_the_path_you_need>

.NET Core publish work only with Production environment

I have .NET Core 3.1 app and I publish it to file system.
In web.config file I have:
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
And in launchSettings.json I have:
"App": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5000/"
}
When I launch app dotnet App.dll I have error with wrong DB connection but if I copy appsettings.Production.json file then everything is fine. What's wrong? Why I can't use Development environment?
How to set up Development environment properly? What did I miss?
Strange thing, when I publish from VS, it always used Production environment although I set Development everywhere where I can (web.config, launchSettings.json, .pubxml, .csproj).
But when I use .NET CLI and execute dotnet publish then it uses Development environment by default, I set Development environment only in launchSettings.json file.
Not sure if it's VS bug but for me using of .NET CLI was solution of problem.

Trying to set environment in VSCode launch.json on OS X

I'm building an ASP.Net Core RC2 MVC Application on OS X
I don't seem to be able to set my environment for development
I think I should be able to add within my launch.json file:
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
I've tried adding it within the "name": ".NET Core Launch (web)" section. But "env" is not recognised. The version of the launch.json file is set as "version": "0.2.0", The error i get shown in the editor is Property env is not allowed
Has anyone got this working on OS X?
Thanks.
The issue is with OmniSharp for VS Code, as found at Issue #172 on their repo.
If you install their most recent preview release, the environment variable will work as intended. Download the VSIX file, and open it using the Open File dialog in VS Code. When the official release comes out, it will still suggest extension updates as per normal.

Errors creating ASP.NET Core 1 application

I have VS2015 and I am attempting to create an ASP.NET Core 1.0 application.
I select the template and also leave the defaults (host in azure and identity security set to individual).
I enter the details for the Azure instance and then when the project loads in VS2015 it errors straight away against DNX 4.5.1 and DNX Core 5.0. I have tried package restore but no luck. in the project.json file I have:
{
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
#Adrien got me onto the right track. I used the Nuget command line to install the latest release for Newtonsoft.Json. It successfully installed and I could see the change to the version in the project.json file. However I still had the same error displaying. Although it had updated the main file, the project.lock.json file didn't get it's references updated at the same time. I had to close my project and re-open before the reference change took effect to the lock file.

ASP.NET 5 RC1 Project Differences

I just created another test project in VS 2015 using ASP.NET 5 MVC 6. Last time I was using beta-7 of the runtime. This time however, I am using RC1.
project.json file for RC1 version:
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
}
project.json file for beta-7 version:
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
}
Kestrel is a mono platform and I have no idea why the default template would set this up as opposed to IIS or IIS Express? Can someone explain how to correctly configure IIS (preferable) and IIS Express for Web apps running on RC1? Although the RC1 site is running and showing in the IIS Express task bar, why the Kestrel config entry?
What are the steps to switch to full IIS and CoreCLR?
ASP.NET 5 ships with support for 3 different servers:
Microsoft.AspNet.Server.IIS
Microsoft.AspNet.Server.WebListener (WebListener)
Microsoft.AspNet.Server.Kestrel (Kestrel)
You can configure your application to be hosted by any or all of these servers by specifying commands in your project.json file.
When launching a server, you can provide it with some configuration options. This can be done directly using command line parameters, or a configuration file containing the settings can be specified. The Microsoft.AspNet.Hosting command supports parameters for the server to use (such as Kestrel or WebListener) as well as a server.urls configuration key, which should contain a semicolon-separated list of URL prefixes the server should handle.
The project.json file demonstrates how to pass the server.urls parameter directly:
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
Alternately, a configuration file can be referenced, instead:
"kestrel": "Microsoft.AspNet.Hosting --config hosting.ini"
Then, hosting.ini can include the settings the server will use (including the server parameter, as well):
server=Kestrel
server.urls=http://localhost:5000
Reference and more detailed information here:
http://docs.asp.net/en/latest/fundamentals/servers.html
Also, the Configure() method in new Startup class allows specifying which handler to use and you can specify
app.UseIISPlatformHandler()
with appropriate parameters to use IIS hosting.
Your application is most likely running under IIS (express) hosting because you might have IIS or IIS Express selected in the "Run" option (in the toolbar at the top in Visual Studio). If you want to use Kestrel, change that to "web" and then it will pick what's specified in the project.json configuration under command->web.

Resources