C
C#7mo 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
Angius7mo ago
Why does it not work elsewhere, exactly? Any errors or something?
felix
felix7mo ago
Its not opening, instantly closing
Angius
Angius7mo 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 User7mo ago
Message Not Public
Sign In & Join Server To View
felix
felix7mo ago
I need the datas hmm :/
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Angius
Angius7mo ago
Ah, so you were using just the exe?
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX7mo 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
Angius7mo ago
And you will need all the files that you get from the publishing Or, yeah, a singlefile build
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
felix
felix7mo 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 User7mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX7mo ago
Use the /close command to mark a forum thread as answered
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts
Unity Movement systemEverything works except for going up hills. It kinda lags out and does it very slowely only pushing ASP.Net Core MVC Razor view rendering data from controller with dynamic castingIn my MVC application I'm using IEnumerable interface inside my repository for the database model, a"ExtensionlessUrlHandler-Integrated-4.0"I've been struggling with getting my local IIS on Win 11 to host some older (4.5.1) MVC applicationsASP .NET 7 - Testing a JWT Token GeneratorI have an ASP .NET web api which calls a CreateToken() method inside a TokenService to generate a JWCount the number of sequences of characters "cd" in a line and delete those before itletter 'b' (reHow to do it in c#... I would be very grateful if anyone could help with a sample codeInconsistent accessibility: property type 'Exercises.Register.Gender' is less accessible than properI honestly have no clue how it's having issues with accessibility when both classes are within the scookie clicker storeHello i am here ones again asking for help. My store buttons need to be dissabled if i don't have teWhere to change working directory in VS2022?How do you change the working directory for a project in Visual Studio? The project I'm working on Can you store a unique function within a class?I'm new to working with classes in C# and would like to be able to use them for a game I'm working oCan I add elements to an array while running the code?Hi there! Bashing my head in with my beginner C# assignment. From the instructions they want us to