0

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) Running pm2 status suggests that everything is fine

However, running

pm2 logs 2 --lines 50

showed me this error

enter image description here

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"
            }
        }
    }
}
Eric Webb
  • 361
  • 3
  • 10
  • Is the solution in this post relevant to your case, [Ubuntu 19.04 fresh install - 'N/A' is not a valid version string](https://github.com/dotnet/core/issues/3909) – quaabaam Jul 26 '23 at 00:37
  • @quaabaam I had tried "export version=1" to set the environment variable to a number (previously, no value was set). Pm2 restart after that fact unfortunately gave me the same results – Eric Webb Jul 26 '23 at 01:11
  • 1
    try instead of `dotnet watch` just to run `dotnet your_assembly_name.dll` – Ryan Jul 26 '23 at 01:44
  • @Ryan Where would I find my .dll files? I don't see any within my project's directory, even on localhost. I'll edit the question to include my directory structure. EDIT: Found the dll, will try – Eric Webb Jul 26 '23 at 01:53
  • @Ryan so that seems to have worked... sort of. The initial start (replacing my dotnet watch run command with "dotnet path/to/my/dll" launched it... on port 8080. After a pm2 restart, it booted up again, only on port 5000. Is there a way to ensure it runs on a specific port? I updated the question to include my launchSettings.json. Thank you for your help! – Eric Webb Jul 26 '23 at 02:09
  • 1
    @EricWebb, launchSettings.json has nothing to do with launching apps outside of IDEs. Regarding urls to be specified, there are several ways: [--urls option or through configuration](https://stackoverflow.com/questions/37365277/how-to-specify-the-port-an-asp-net-core-application-is-hosted-on) See second answer there. – Ryan Jul 26 '23 at 02:17
  • 1
    So, in simplest case you want to run it as `"dotnet path/to/my/dll --urls=http://*:8082"` – Ryan Jul 26 '23 at 02:27
  • 1
    @Ryan That fixed it, thank you so much! If you wanted to combine the dotnet assembly.dll suggestion and the suggestion for setting the --urls flag, I'll happily accept it as the answer! – Eric Webb Jul 26 '23 at 02:31
  • @EricWebb, okay. – Ryan Jul 26 '23 at 02:35

1 Answers1

3

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.

Ryan
  • 609
  • 6
  • 13