I’m trying to deploy an Asp.Net Core project to a ubuntu 22.04.2 server. I cloned my git repo, built it with 0 compilation errors, and spawned a process with pm2 with the following command
pm2 start --name "dotnet" "dotnet watch run --project 'Factor Earth Forms 2 dotnet api.csproj'"
Everything was working great! while working on setting up ssl certs and nginx, I ran
pm2 reload 2
(2 was my process id)
and much to my dismay, the process was no longer running. Running
pm2 status
suggests that everything is fine (it’s process id 7 here, I was troubleshooting a while before writing this question)
However, running
pm2 logs 2 --lines 50
showed me this error
Specifically
/usr/lib/dotnet/sdk/7.0.109/NuGet.targets(132,5): error : 'N/A' is not a valid version string. (Parameter 'value') [/home/ubuntu/record-dotnet/Factor Earth Forms 2 dotnet api.csproj]
I’m not super familiar with the internal workings of c# apps (I’m a nodejs developer who needed a specific c# library, so I set up this to be an endpoint I could use). My .csproj file has no mention of a "version" or "value" (see below). I ran
pm2 delete 2
and re-made the process. Once again, it was working fine (I tested it with postman, my routes were working on the server, not just my localhost. Upon pm2 reload though, the same error comes up. Is there something evident that I’m doing wrong? I want to run the process with pm2 so that if a fatal error occurs, the process restarts itself. That said, I’m not tied to pm2 necessarily, it’s just what I’m familiar with. Does anybody know what I can do to fix this, or know an alternative to pm2 that I could use that wouldn’t have this issue?
.csproj
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Factor_Earth_Forms_2_dotnet_api</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.8" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
Program.cs (my launch file)
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure thecs HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
// app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
launchSettings.json
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:63518",
"sslPort": 44326
}
},
"profiles": {
"Factor_Earth_Forms_2_dotnet_api": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:8082",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
2
Answers
its 2pm not pm2…. regardless i dont think you should be having trouble after 2pm.
Instead of launching app in watch mode, you want a classic command to launch dotnet apps:
dotnet path/to/my/dll
One of the options to specify urls to be used, is via
--urls
option:dotnet path/to/my/dll --urls=http://*:8082
You can also use configuration file for that purpose.
PS: Documentation for configuring urls.