-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
I can use MSBuild style properties in VS and VSCode for command line arguments, and when I debug or run, the IDEs will expand the variables, meaning my app sees the value. While dotnet run
on the command line will find and use launchSettings.json, it treats the property as an empty stringdoes not expand the property that works in the IDEs.
I can't find any documentation on launchSettings.json's commandLineArgs, so if it's intentional that properties that work in VS and VSCode should not work on the CLI, I can't find evidence, and I don't find it intuitive. Asking Copilot, it gave me an answer that's factually wrong. Using bing search results, the closest docs I could find were the container tools launch settings docs, but it doesn't say what replacement tokens are available for CommandLineArgs. Going to dotnet run command's docs, it has a link to asp.net core's docs (which bing itself didn't show on the first page of search results), and when I follow the link, their docs don't mention commandLineArgs at all.
Doing dotnet run -bl
does create a binlog, but it stops at the build, which makes sense. But the properties available in the build are being replaced with empty strings at run, and I can't figure out how else to debug to investigate for myself which properties, if any, are available when running from the CLI.
My end goal is that I have a console app that takes an output directory as a command line argument. I want to set up the default launch settings to use a specific directory within the source control repo, so it doesn't matter if I launch from an IDE, or if I launch on the command line with the working directory being the project directory, the solution directory, or elsewhere, in all cases the default argument provided to the console app is consistently the same location.
To Reproduce
src/MyApp/Program.cs
if (args.Length != 1)
{
Console.WriteLine("Usage: Program <input>");
return 1;
}
Console.WriteLine("Raw argument: " + args[0]);
var path = Path.GetFullPath(args[0]);
Console.WriteLine($"Repo root: {path}");
return 0;
the csproj is just the default dotnet new console
. no changes needed.
src/MyApp/Properties/launchSettings.json
{
"profiles": {
"launchSettings": {
"commandName": "Project",
"commandLineArgs": "$(ProjectDir)\\..\\..\\"
}
}
}
No matter how I run the project, when launchSettings.json is used, I want the "repo root" output to be the same. I also tried MSBuildProjectDirectory, which is an MSBuild reserved property that always has a value (when using MSBuild, obviously).
Exceptions (if any)
N/A
Further technical details
details of dotnet --info
.NET SDK: Version: 10.0.100-preview.6.25358.103 Commit: 75972a5ba7 Workload version: 10.0.100-manifests.cc13e7a2 MSBuild version: 17.15.0-preview-25358-103+75972a5ba
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100-preview.6.25358.103\
.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.
Host:
Version: 10.0.0-preview.6.25358.103
Architecture: x64
Commit: 75972a5ba7
.NET SDKs installed:
8.0.413 [C:\Program Files\dotnet\sdk]
9.0.304 [C:\Program Files\dotnet\sdk]
10.0.100-preview.6.25358.103 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0-preview.6.25358.103 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0-preview.6.25358.103 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0-preview.6.25358.103 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download