✅ set "dotnet run" to always run in release

how do i do that?
36 Replies
it’s raining outside
(on the command line)
LPeter1997
LPeter19973mo ago
--configuration Release?
it’s raining outside
always run
so i dont need to add those extra arguments it's just an in-built setting
LPeter1997
LPeter19973mo 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
it’s raining outside
not an MSBuild expert
is there anyone here who is?
LPeter1997
LPeter19973mo ago
My question would be, why do you insist on local Release builds
it’s raining outside
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
LPeter19973mo 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
it’s raining outside
can i run that from vscode?
LPeter1997
LPeter19973mo ago
Sure you can
it’s raining outside
oh wow how then? lemme check if there are any extensions hold on also is powershell the same as cmd
LPeter1997
LPeter19973mo 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
it’s raining outside
ooh do tell me more oh ok. i'll just use PS then wait how do you add to launchsettings?
LPeter1997
LPeter19973mo ago
You might not even need it, let me try to do this manually in VSC
it’s raining outside
because this is all i have
No description
it’s raining outside
👍 @LPeter1997 you good?
LPeter1997
LPeter19973mo ago
I've just installed the new VSC extension, I'm still trying to figure out the new json schema they have
sibber
sibber3mo ago
echo "dotnet run --configuration Release" > runrelease.cmd
./runrelease.cmd
echo "dotnet run --configuration Release" > runrelease.cmd
./runrelease.cmd
LPeter1997
LPeter19973mo ago
Read back a little 😛
sibber
sibber3mo ago
oh oops you want a launch profile?
it’s raining outside
yeah (idk what that is)
sibber
sibber3mo ago
so you can run from vscode i recommend just a script tho easier you dont even need a script just ⬆️
it’s raining outside
yeah sure just hit the play button and see results yk
sibber
sibber3mo ago
that wont add a play button iirc just allows you to run from the command bar thing
it’s raining outside
how do you add that then
sibber
sibber3mo ago
probably with an extention but youre putting too much effort into this'
LPeter1997
LPeter19973mo 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
it’s raining outside
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
LPeter19973mo ago
That will run it as part of your pre-launch task instead
it’s raining outside
whats a pre-launch task?
LPeter1997
LPeter19973mo ago
A task it performs... drum roll ... before launching
it’s raining outside
ohh and forgive me if i sound naggy or annoying, but how does that relate to the run button?
LPeter1997
LPeter19973mo 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
it’s raining outside
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
LPeter19973mo 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)
it’s raining outside
ah ok works fine now
Want results from more Discord servers?
Add your server