C
C#13mo ago
felix

✅ Make C# Application work directory independent, relativ work directory for exe file

Hello guys, I want my C# Application Executable Everywhere, also on other PC's, currently my exe file is only working in my work directory. I know its a very beginner question, but I am new :) Thanks.. c:
15 Replies
Angius
Angius13mo ago
Why does it not work elsewhere, exactly? Any errors or something?
felix
felixOP13mo ago
Its not opening, instantly closing
Angius
Angius13mo ago
Well, my first idea is that you might be using absolute paths somewhere and not catching the exception if the file could not be found So it just crashes
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
felix
felixOP13mo ago
I need the datas hmm :/
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Angius
Angius13mo ago
Ah, so you were using just the exe?
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX13mo ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -p:PublishSingleFile=true implies --self-contained true. Add --self-contained false to publish as runtime-dependent. -r RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
but to target multiple RIDs, you have to use dotnet publish with the -r option for each RID. You can also add -p:IncludeNativeLibrariesForSelfExtract=true to include native libraries (like Common Language Runtime dlls) in the output executable. You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples. Single file publishing | Runtime Identifier (RID) catalog | dotnet publish
Angius
Angius13mo ago
And you will need all the files that you get from the publishing Or, yeah, a singlefile build
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
felix
felixOP13mo ago
yea DONE It worked Lol good to know Thanks guys for your help and time I am appreciate it :) @TeBeCo - @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX13mo ago
Use the /close command to mark a forum thread as answered
Unknown User
Unknown User13mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server