ı wanna deploy a project to google cloud app engine but encountered a problem.
First, I created a folder in app engine ssh and created a net6 project in this folder, then "dotnet restore" this project.
I restored it with code. Then I published it with the code "dotnet publish -c Release". Then I added the Dockerfile and app.yaml files that I showed into the publish file. Also, my launchSettings.json file is as follows.
Although I do all these configurations and run the "gcloud app deploy" code under the publish folder, I get the log image as below and after saying "gcloud app browse" I get the "502 Bad Gateway" nginx error on the page I go to. What is the reason of this.
Logs :
Dockerfile :
ADD / /app
ENV ASPNETCORE_URLS=http://localhost:8080
WORKDIR /app
ENTRYPOINT [ "dotnet", "giveawayproject.dll"]
app.yaml :
runtime: custom
env: flex
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/dotnet/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 2
memory_gb: 6
disk_size_gb: 30
env_variables:
# The __ in My__Greeting will be translated to a : by ASP.NET.
My__Greeting: Hello AppEngine!
launchSettings.json :
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8080",
"sslPort": 44302
}
},
"profiles": {
"Wizz.Giveaway.Mvc": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:8080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
This is how I modified the dockerfile. The application worked. As far as I understand, the port was not working because I did not export it.
FROM mcr.microsoft.com/dotnet/aspnet:6.0
ADD / /app
EXPOSE 8080
ENV ASPNETCORE_URLS=http://*:8080
WORKDIR /app
ENTRYPOINT [ "dotnet", "giveawayproject.dll"]
Related
VS 2019
ASP.NET Core 3.1
I have developed a Web App locally and now I am ready to deploy to an Azure Staging environment.
My Web App was originally .Net (not Core) and I had not problems deploying it.
How to I tell the deployment process to use the "Staging" environment?
My launchSettings.json contains the following:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:59000",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
I have a appSettings.Staging.json pointing to the Staging database...
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Warning"
}
},
"ConnectionStrings": {
"DbConnection": "Data Source=myapp.database.windows.net;Initial Catalog=MyAppCoreStaging;user id=myappstepadmin;password=mypassword;MultipleActiveResultSets=True"
}
}
But I am not sure how to tell it to use Staging when I deploy.
At the moment when I deploy, the browser starts up on the page and I get:
HTTP Error 500.30 - ANCM In-Process Start Failure
Common solutions to this issue:
The application failed to start
The application started but then stopped
The application started but threw an exception during startup
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=2028265
Is there something I need to configure on Azure to use the Staging?
Since you are deploying to Azure and didn't specify that you are using a CI/CD Pipeline as your method of publishing, I assume that you are using the publishing profiles provided from Azure portal directly in Visual Studio.
In the Publish dialog, click on Edit -> settings -> Configuration and select Stage
In your Program.cs, your CreateWebHostBuilder (assuming you are using ASP.NET Core 3.0+; it's also possible for 2.2 but it's not IWebHostBuilder), you can specify that the appsettings file should be dependent on your solution configuration:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseEnvironment(Environment);
where Environment can be a property with preprocessor directives:
public static string Environment
{
get
{
string environmentName;
#if DEBUG
environmentName = "development";
#elif STAGE
environmentName = "staging";
#elif RELEASE
environmentName = "production";
#endif
return environmentName;
}
}
If you use a build pipeline, you should look at this.
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '-o $(build.artifactstagingdirectory) /p:EnvironmentName=Staging'
For some reason, Visual Studio 2017 (version 15.9.12), refuses to load ASP.Net Dotnet Core 2.2 pages in non-ssl. It automatically appends an s to http as in https://localhost:15777 even though Enable SSL is unchecked and the Launch brower path is set to http://localhost:15777 (or for Kestrel, it's set to http://localhost:55333).
The launchSettings.json file looks like so (as you can see, it's set correctly, but completely ignored).
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:15777",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "http://localhost:15777",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Nop.Web": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:55333"
}
}
}
This, didn't do this a week ago, and I've scoured posts here and there looking for an answer. Obviously, there is a bug somewhere, so I'm looking for a hack to make Visual Studio, IIS Express or Kestrel work like it's supposed to.
Any ideas?
it doesn't relate to visual studio.
you have to remove the app.UseHttpsRedirecttion(); in Startup.cs file
also, you may run your Release and because of app.UseHsts() it will redirect to https until its time expires.
try to clear your browser security cache.
you can clear hsts security cache by going to chrome://net-internals/#hsts and delete the address you want.
In JetBrains Rider, we can either manually create a profile to run a .NET Core Web app or use launchSettings.json file if it is included in the project. However, when I manually create a profile it does not build the tests projects but when I use the launchSettings.json it tries to build the tests projects (it's probably just running dotnet build without any filters). I am wondering what do I need to add to my launchSettings.json to exclude building the tests projects. Thank you
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:20169",
"sslPort": 44329
}
},
"profiles": {
"Web": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Localhost"
}
}
}
}
Unfortunately, that's just a bug in Rider: https://youtrack.jetbrains.com/issue/RIDER-23780
It should work as you describe (e.g. it should only build the projects required for the program to run if you click the "Run" button), but it doesn't work for Launch Settings yet.
The workaround is to either create a ".NET Project" run configuration instead of the "Launch Settings" one, or to manually exclude the projects from build.
I'm developing a Web API with .NET Core in macOS with deployment to Linux. I have absolutely no interest in using the browser. However, when building and running from Visual Studio Code (Debug or not), the browser launches every time.
I have to close the tab, remove the browser out of the way, go to Paw, where I actually test the API, then go back to VS Code.
It's really annoying doing this every time.
Isn't there some configuration to disable browser launch?
Thanks
It is changed in version 0.2.0.
Just comment out the below lines.
// "serverReadyAction": {
// "action": "openExternally",
// "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
// },
Short Answer
Open the .vscode/launch.json file and disable launchBrowser.
More Details
dotnet new webapi
Open VS Code.
Add required assets to build and debug.
At this point, there is a .vscode directory that contains a launch.json file. Open that file and disable or delete the following.
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
See also: https://code.visualstudio.com/docs/editor/debugging#_launch-configurations
Short Answer
Open the Properties/launchSettings.json file and set "launchBrowser": false. It works for Visual Studio 2019.
More Details
Go to the project location
Open the Properties/launchSettings.json
Set "launchBrowser": false
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"launchUrl": "weatherforecast",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"MyApi": {
"commandName": "Project",
"launchBrowser": false,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
Just to add, it works for Visual Studio 2017 as well (Not only VS Code). The file is called launchSettings.json, and is located inside the Properties folder of the project.
For me, commenting out the serverReadyAction block in vscode/launch.json worked. I believe the launchBrowser is deprecated.
More info : Starting a Web Browser
In my case, the auto-generated launch.json contained this section:
"serverReadyAction": {
"action": "openExternally",
"pattern": "^\\s*Now listening on:\\s+(https?://\\S+)"
},
So the browser was keeping launching even if I removed the "launchBrowser" or set its "enabled" property to false.
Deleting the "serverReadyAction" section solved my issue.
I am using Visual Studio with ASP.NET Core and run the website using just F5 or Ctrl+F5 (not using the command line directly). I would like to use the "dotnet watch" functionality to make sure all changes are picked up on the fly to avoid starting the server again. It seems that with the command line you would use "dotnet watch run" for this, but Visual Studio uses launchSettings.json and does it behind the scenes if I understand it correctly.
How can I wire up "dotnet watch" there?
If you want to use ASP.NET 2.x or 3.x you need to change it a bit.
The watch tool is a global tool now and you don't need to add it as a reference any longer
The syntax is slightly different
"Watch": {
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch run",
"launchBrowser": true,
"launchUrl": "http://localhost:5000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
For .Net 5 & 6
In VisualStudio 2019
Go to Tools > ⚙ Options > Projects and Solutions > ASP .NET Core
Select Auto build and refresh browser after saving changes in Auto build and refresh option
Press Ctrl + F5 (Start Without Debugging) IMPORTANT: Only works if run without debbuging
Otherwise add this to your launchSettings.json:
{
"iisSettings": {
...
},
"profiles": {
... ,
"Watch": {
"commandName": "Executable",
"executablePath": "dotnet.exe",
"workingDirectory": "$(ProjectDir)",
"commandLineArgs": "watch run"
}
}
}
The automatically generated profile with "commandName":"Project" has all the other properties needed: launchBrowser, applicationUrl, environmentVariables, dotnetRunMessages and hotReloadProfile. Any modifications should be made there.
Corresponding Blog-Post from Juan Cruz Fiant: https://dev.to/juxant/auto-refresh-with-dotnet-watch-for-asp-net-core-projects-20no
Open launchSettings.json and add this to profiles.
"Watch": {
"executablePath": "C:\\Program Files\\dotnet\\dotnet.exe",
"commandLineArgs": "watch run",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
Open project.json and add this to tools.
"Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final"
After restoring, we can Watch from within Visual Studio.
Just one little correction to #Flynn`s answer. You need to add an
"commandName": "Executable"
argument to the "Watch" profile. Also to define the urls you should define them not in the "Watch" profile, but in the profile with
"commandName": "Program"
argument (it is present in the default launchsettings.json, created by the Visual Studio project templates, so, your launchsettings.json finally looks like this:
"AnyTest.WebClient": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"launchUrl": "",
"applicationUrl": "https://localhost:44353;http://localhost:51895",
"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
},
"Watch": {
"commandName": "Executable",
"workingDirectory": "$(ProjectDir)",
"executablePath": "dotnet.exe",
"commandLineArgs": "watch run"
}
I kept the launchBrowser argument in the Program profile, but browser in not launched. But if this argument is present in the Executable profile, the browser is not launched too and I found no way to launch it automatically.
The accepted answer works, but it's 4+ years old. So here's how you make it work for Visual Studio 2019 (v16.8.5 in my case).
Inside the profiles section of launchSettings.json, you add a new profile, let's say "API Watch", with this content:
"API Watch": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "watch run",
"workingDirectory": "$(ProjectDir)",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"dotnetRunMessages": "true"
}
And then you go and select it in the Build profiles dropdown:
Now when you run it, regardless if with or without Debug mode on, the re-build and browser refresh (I use the Swagger UI as default page) happens automatically.
One note about using it in Debug mode, is that Visual Studio will mark the changes with green and will say that they won't be applied until a restart happens. I can confirm that this is not true and that the changes are really reflected by the auto rebuild feature of dotnet watch run. It's just that VS 2019 gets confused and treats things from the old (standard) perspective.
"Watch": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000/",
"commandLineArgs": "watch run",
"workingDirectory": "$(ProjectDir)",
"executablePath": "dotnet.exe",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
This one will work and launch the browser too. It works because of the "commandName": "Project" line, which means it will be launching with the Kestrel server.
To anyone else reading these really old answers and wondering if it is baked-in yet, then you should read this blog post from Nov 22, 2020.
https://dev.to/juxant/auto-refresh-with-dotnet-watch-for-asp-net-core-projects-20no
Visual Studio 2019 now has a setting for ASP.NET Core to refresh when using IIS Express. By default it is not enabled.
You can still use the launchSettings.json files as described in the article.
Open launchSettings.json and add this to profiles.
"Watch": {
"executablePath": "dotnet.exe",
"commandLineArgs": "watch --project ..\\..\\..\\YourProject.csproj run",
"launchBrowser": true,
"launchUrl": "http://localhost:5000/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
In Visual Studio 2019
{
"profiles": {
"msteamsimc": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "watch run",
"workingDirectory": "$(ProjectDir)",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
},
"dotnetRunMessages": "true",
"applicationUrl": "https://localhost:5001;http://localhost:5000"
}
}
}
here an image for confg
here an image for working project 2021-01-11