✅ set "dotnet run" to always run in release

how do i do that?
36 Replies
slowly losing it
slowly losing itOP5mo ago
(on the command line)
LPeter1997
LPeter19975mo ago
--configuration Release?
slowly losing it
slowly losing itOP5mo ago
always run
so i dont need to add those extra arguments it's just an in-built setting
LPeter1997
LPeter19975mo ago
Shove it in a script and call ./build.ps1 🤷 I don't recommend defaulting to release anyway, not a lot of win. Most of the time you'll only need a release build when publishing to save on PDB size I'm 99% sure you could do some hackery like
<PropertyGroup Condition="'$(Configuration)' == ''">
<Configuration>Release</Configuration>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == ''">
<Configuration>Release</Configuration>
</PropertyGroup>
But Idk about that, not an MSBuild expert to say that this will actually do what you want
slowly losing it
slowly losing itOP5mo ago
not an MSBuild expert
is there anyone here who is?
LPeter1997
LPeter19975mo ago
My question would be, why do you insist on local Release builds
slowly losing it
slowly losing itOP5mo ago
im writing a chess engine and when i do something called a "perft test" (make a function that traverses the game tree and verifies your code works fine), i got about 50,000 nodes per second (extremely slow, i was seeing people get hundreds of millions of nodes per second) and thats because i was (unknowingly) running it in debug mode. running it in release got me 12-18mnps (i have sub-optimal hardware so thats expected)
LPeter1997
LPeter19975mo ago
Wouldn't just having a powershell script to run it for you suffice? perftest.ps1 could just invoke dotnet run --configuration Release for you
slowly losing it
slowly losing itOP5mo ago
can i run that from vscode?
LPeter1997
LPeter19975mo ago
Sure you can
slowly losing it
slowly losing itOP5mo ago
oh wow how then? lemme check if there are any extensions hold on also is powershell the same as cmd
LPeter1997
LPeter19975mo ago
No need, you can just plop it into your launchsettings Well there's the old windows command line which is generally called CMD, but PowerShell is a .NET-based shell In this case it doesn't matter which one you use
slowly losing it
slowly losing itOP5mo ago
ooh do tell me more oh ok. i'll just use PS then wait how do you add to launchsettings?
LPeter1997
LPeter19975mo ago
You might not even need it, let me try to do this manually in VSC
slowly losing it
slowly losing itOP5mo ago
because this is all i have
No description
slowly losing it
slowly losing itOP5mo ago
👍 @LPeter1997 you good?
LPeter1997
LPeter19975mo ago
I've just installed the new VSC extension, I'm still trying to figure out the new json schema they have
sibber
sibber5mo ago
echo "dotnet run --configuration Release" > runrelease.cmd
./runrelease.cmd
echo "dotnet run --configuration Release" > runrelease.cmd
./runrelease.cmd
LPeter1997
LPeter19975mo ago
Read back a little 😛
sibber
sibber5mo ago
oh oops you want a launch profile?
slowly losing it
slowly losing itOP5mo ago
yeah (idk what that is)
sibber
sibber5mo ago
so you can run from vscode i recommend just a script tho easier you dont even need a script just ⬆️
slowly losing it
slowly losing itOP5mo ago
yeah sure just hit the play button and see results yk
sibber
sibber5mo ago
that wont add a play button iirc just allows you to run from the command bar thing
slowly losing it
slowly losing itOP5mo ago
how do you add that then
sibber
sibber5mo ago
probably with an extention but youre putting too much effort into this'
LPeter1997
LPeter19975mo ago
I mean it should be trivial to add a launchsetting that just specifies release but C# DevKit of course provides absolute dogshit documentation The schema doesn't even seem to include config as an option. You can do a pre-launch task to build a release version, won't use it to run that I think I got it So within the .vscode folder, you'd define a task to build a release. I did it like so (tasks.json):
{
"version": "2.0.0",
"tasks": [
{
"label": "dotnet: build release",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/ConsoleApp1.csproj",
"-c",
"Release"
],
"problemMatcher": "$msCompile"
}
]
}
{
"version": "2.0.0",
"tasks": [
{
"label": "dotnet: build release",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/ConsoleApp1.csproj",
"-c",
"Release"
],
"problemMatcher": "$msCompile"
}
]
}
And also within .vscode, defined a launchsetting to use the output DLL of the build (launch.json):
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Perftest Launch",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build release",
"program": "${workspaceFolder}/bin/Release/net8.0/ConsoleApp1.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
},
]
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Perftest Launch",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: build release",
"program": "${workspaceFolder}/bin/Release/net8.0/ConsoleApp1.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
},
]
}
I think this should work, it worked for me
slowly losing it
slowly losing itOP5mo ago
it keeps fucking building (in the default way) i changed it to run in release
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "dotnet: run release",
"command": "dotnet",
"type": "process",
"args": [
"run",
"chess.csproj",
"-c",
"Release"
],
"problemMatcher": "$msCompile"
}
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "dotnet: run release",
"command": "dotnet",
"type": "process",
"args": [
"run",
"chess.csproj",
"-c",
"Release"
],
"problemMatcher": "$msCompile"
}
]
}
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch C#",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: run release",
"program": "${workspaceFolder}/bin/Release/net8.0/chess.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
},
]
}
// launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch C#",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "dotnet: run release",
"program": "${workspaceFolder}/bin/Release/net8.0/chess.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
},
]
}
LPeter1997
LPeter19975mo ago
That will run it as part of your pre-launch task instead
slowly losing it
slowly losing itOP5mo ago
whats a pre-launch task?
LPeter1997
LPeter19975mo ago
A task it performs... drum roll ... before launching
slowly losing it
slowly losing itOP5mo ago
ohh and forgive me if i sound naggy or annoying, but how does that relate to the run button?
LPeter1997
LPeter19975mo ago
Typically build Well to run, you generally build first Tools by default don't use dotnet run to run your thing They first build And then execute the built thing This is what dotnet run does as well in the background The main reason for this separation is so that a debug adapter and a debugger can hook into your running app showing you the pretty crashes and whatnot
slowly losing it
slowly losing itOP5mo ago
ohh ok i see ahh ok i see it now so how do i run it in release then? wait i can just clone the extension and edit the arguments wow programming is amazing
LPeter1997
LPeter19975mo ago
The launch thing I gave you should launch the release built DLL (Make sure that the launch setting with that name is selected in the debug/run tab)
slowly losing it
slowly losing itOP5mo ago
ah ok works fine now

Did you find this page helpful?