C
C#β€’17mo ago
maria 🌟

❔ Net 7 How to output one exe without dlls

Halp $singlefile didnt worked
117 Replies
MODiX
MODiXβ€’17mo ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -r|--runtime 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. https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file https://docs.microsoft.com/en-us/dotnet/core/rid-catalog https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish
Create a single file for application deployment - .NET
Learn what single file application is and why you should consider using this application deployment model.
.NET Runtime Identifier (RID) catalog
Learn about the runtime identifier (RID) and how RIDs are used in .NET.
maria 🌟
maria πŸŒŸβ€’17mo ago
and the exe doenst run without the dll sooo
Thinker
Thinkerβ€’17mo ago
what did you try?
maria 🌟
maria πŸŒŸβ€’17mo ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true
Thinker
Thinkerβ€’17mo ago
you have to replace <runtime identifier> with a... runtime identifier
maria 🌟
maria πŸŒŸβ€’17mo ago
yes i did
Thinker
Thinkerβ€’17mo ago
translate plz
maria 🌟
maria πŸŒŸβ€’17mo ago
done
Thinker
Thinkerβ€’17mo ago
Try adding --self-contained
maria 🌟
maria πŸŒŸβ€’17mo ago
Task "ResolveComReference" is not supported on .NET Core version of MSBuild. Use the MSBuild version of the .NET Framework. See
Thinker
Thinkerβ€’17mo ago
yeah idk what that's about :/
maria 🌟
maria πŸŒŸβ€’17mo ago
thaths because i have windows media player on proyect?
Angius
Angiusβ€’17mo ago
For context: the project was migrated from Fx 4.8 to .NET 7 using the Upgrade Assistant ( #❔ nul )
Thinker
Thinkerβ€’17mo ago
ah
maria 🌟
maria πŸŒŸβ€’17mo ago
finali i just created a new and do it all myself Upgrade Assistant broke everything the output is proyectname.exe and proyectname.dll i just want both only one exe
Thinker
Thinkerβ€’17mo ago
maria 🌟
maria πŸŒŸβ€’17mo ago
oh -c release
Thinker
Thinkerβ€’17mo ago
maria 🌟
maria πŸŒŸβ€’17mo ago
Doenst work :C
maria 🌟
maria πŸŒŸβ€’17mo ago
ResolveComReference Task - MSBuild
Learn how MSBuild uses the ResolveComReference task to take a list of one or more type library names or .tlb files and resolve them to locations on disk.
Thinker
Thinkerβ€’17mo ago
have you tried dotnet publish -c Release -r <rid> --self-contained -p:PublishSingleFile=true? Also can you show your csproj file?
maria 🌟
maria πŸŒŸβ€’17mo ago
thath i was gonna do because i was modifyng it befotre
Thinker
Thinkerβ€’17mo ago
Well afaik you can delete StartupObject, ApplicationIcon, and PlatformTarget, and you can also delete PublishSingleFile and RuntimeIdentifier since you can specify those when running dotnet publish is that the entire file?
maria 🌟
maria πŸŒŸβ€’17mo ago
sry
Thinker
Thinkerβ€’17mo ago
Looks like this is the issue
<ItemGroup>
<COMReference Include="WMPLib">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>0</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>6bf52a50-394a-11d3-b153-00c04f79faa6</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>
<ItemGroup>
<COMReference Include="WMPLib">
<WrapperTool>tlbimp</WrapperTool>
<VersionMinor>0</VersionMinor>
<VersionMajor>1</VersionMajor>
<Guid>6bf52a50-394a-11d3-b153-00c04f79faa6</Guid>
<Lcid>0</Lcid>
<Isolated>false</Isolated>
<EmbedInteropTypes>true</EmbedInteropTypes>
</COMReference>
</ItemGroup>
maria 🌟
maria πŸŒŸβ€’17mo ago
yes but i need it for the music
Thinker
Thinkerβ€’17mo ago
<Exec Command="Obfuscar.Console.exe config.xml" />
are you... running an obfuscator
maria 🌟
maria πŸŒŸβ€’17mo ago
yes 😭
Thinker
Thinkerβ€’17mo ago
well you can get rid of that
maria 🌟
maria πŸŒŸβ€’17mo ago
why
Thinker
Thinkerβ€’17mo ago
obfuscation in .NET is literally useless
maria 🌟
maria πŸŒŸβ€’17mo ago
hmm on framework works
Thinker
Thinkerβ€’17mo ago
yeah, the error message above says that COMReference isn't a thing you can use with modern versions of .NET
maria 🌟
maria πŸŒŸβ€’17mo ago
you can steale whole proyect with a single decompiler
Thinker
Thinkerβ€’17mo ago
yep
maria 🌟
maria πŸŒŸβ€’17mo ago
thaths because i use it then
Thinker
Thinkerβ€’17mo ago
you can still do that with obfuscated code takes a bit more effort, but that ain't gonna stop a determined dataminer
Angius
Angiusβ€’17mo ago
$obfuscation
MODiX
MODiXβ€’17mo ago
"Then finally, there is that question of code privacy. This is a lost cause. There is no transformation that will keep a determined hacker from understanding your program. This turns out to be true for all programs in all languages, it is just more obviously true with JavaScript because it is delivered in source form. The privacy benefit provided by obfuscation is an illusion. If you don’t want people to see your programs, unplug your server." - Douglas Crockford https://softwareengineering.stackexchange.com/a/155133 * Spend your effort on putting proprietary things in your api, and keeping the distributed code as empty as possible * Use AuthN/AuthZ to control who/what/when/etc... * Free obfuscation is worth the amount your paid for it -- it's already broken and most decompilers out there can make sense of it. * Paid ofbuscation will bankrupt you unless you have a very strong revenue stream and can justify the additional cost with gained sales * The "threat" of someone hijacking your UI and shimming it to make it provide them money is not a real threat. If this is legitimate software, you can ruin their business with lawsuits - Cisien
Software Engineering Stack Exchange
Is it important to obfuscate C++ application code?
In the Java world, sometimes it seems to be a problem, but what about C++? Are there different solutions? I was thinking about the fact that someone can replace the C++ library of a specific OS wit...
maria 🌟
maria πŸŒŸβ€’17mo ago
ok so i cant use windows media player yea i nkow
Thinker
Thinkerβ€’17mo ago
oh that's what WMPLib stands for lmao yeah no I think you'll have to find some other way to play music in a console app (...?)
maria 🌟
maria πŸŒŸβ€’17mo ago
Naudio?
Thinker
Thinkerβ€’17mo ago
maria 🌟
maria πŸŒŸβ€’17mo ago
thaths what i said yes
Thinker
Thinkerβ€’17mo ago
(that specific tutorial)
maria 🌟
maria πŸŒŸβ€’17mo ago
this i think will be perfect thanks ok let me try again the compile with single file dotnet publish -c Debug -r win-x64 -p:PublishSingleFile=true i have to run this every time oln cimpile?
Thinker
Thinkerβ€’17mo ago
well, every time you want to publish your app
maria 🌟
maria πŸŒŸβ€’17mo ago
but just i want to compile in just one file
Thinker
Thinkerβ€’17mo ago
ex. when you release a new version yeah, dotnet publish -c Release -r <rid> --self-contained -p:PublishSingleFile=true will publish your entire app into a single executable file
maria 🌟
maria πŸŒŸβ€’17mo ago
now i got another error
Thinker
Thinkerβ€’17mo ago
--self-contained
maria 🌟
maria πŸŒŸβ€’17mo ago
PM> Send a message on "Net 7 How to output one exe without dlls" Submit : The term 'Submit' is not recognized as the name of a cmdlet, function, script file, or executable program. Check if you typed the name correctly, or if you included a path, check that the path is correct and try again. Online: 1 Character: 1 + Send a message on "Net 7 How to output one exe without dlls" +~~ + CategoryInfo : ObjectNotFound: (Send:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException oh nothing im stupid dotnet publish -c Debug -r win-x64 -p:PublishSingleFile=true --self-contained wtf 147 MB of file
Thinker
Thinkerβ€’17mo ago
yeah, since single-file app have to pack all the DLLs as well as the entire runtime into the exe, the file sizes tend to be a couple orders of magnitudes larger than regular apps and that's just an inherent part of single-file executables
maria 🌟
maria πŸŒŸβ€’17mo ago
on framework and costura fody was 2 mb .... a couple
maria 🌟
maria πŸŒŸβ€’17mo ago
i got this error
maria 🌟
maria πŸŒŸβ€’17mo ago
i cant start thath on framework worked
Thinker
Thinkerβ€’17mo ago
afaik you have to use the Powershell setting for Process to be able to start URLs
maria 🌟
maria πŸŒŸβ€’17mo ago
what
Thinker
Thinkerβ€’17mo ago
Process.Start(new ProcessStartInfo()
{
UseShellExecute = true,
FileName = "https://github.com/dotnet/roslyn"
});
Process.Start(new ProcessStartInfo()
{
UseShellExecute = true,
FileName = "https://github.com/dotnet/roslyn"
});
maria 🌟
maria πŸŒŸβ€’17mo ago
process start doenst have use shell executed enabled by default?
Thinker
Thinkerβ€’17mo ago
apparently not
maria 🌟
maria πŸŒŸβ€’17mo ago
but on framework yes 😭
Thinker
Thinkerβ€’17mo ago
idk Framework is weird
maria 🌟
maria πŸŒŸβ€’17mo ago
there is no way to be packed as 1 file without packing whole net libraries just the program dll and the nuget dependencyes
Thinker
Thinkerβ€’17mo ago
well, .NET libraries are essentially the same as Nuget dependencies They're all just... DLLs
maria 🌟
maria πŸŒŸβ€’17mo ago
but are alredy installed on computer
Thinker
Thinkerβ€’17mo ago
What is?
maria 🌟
maria πŸŒŸβ€’17mo ago
yes like framework is alredy installed on windows
Thinker
Thinkerβ€’17mo ago
What exactly do you want? Do you just want to publish the app as a single exe file? Do you want the end user to have to install the .NET runtime or not?
maria 🌟
maria πŸŒŸβ€’17mo ago
Do you want the end user to have to install the .NET runtime > yes
i prefere thath thath sending half gigabyte file
Thinker
Thinkerβ€’17mo ago
Then you can get rid of the -p:PublishSingleFile=true thing
maria 🌟
maria πŸŒŸβ€’17mo ago
but i just want the exe and the dll in a single file
Thinker
Thinkerβ€’17mo ago
hold on
maria 🌟
maria πŸŒŸβ€’17mo ago
just theese 2
Thinker
Thinkerβ€’17mo ago
If you do dotnet publish -c Release -r <rid> --no-self-contained then you'll get only the exe and app DLL and all the runtime dependencies will be required to exist on the system but as far as I can tell, you can't only get the app DLL into the exe @Angius you know anything?
maria 🌟
maria πŸŒŸβ€’17mo ago
i just want the exe
Thinker
Thinkerβ€’17mo ago
So you want the exe, but not any libraries packed into it?
maria 🌟
maria πŸŒŸβ€’17mo ago
i just want to run an silgle exe and work without any other dll on the folder like a single exe you download and you run
Thinker
Thinkerβ€’17mo ago
Well, that's what single-file does, but the resulting exe is massive Still, it's not very difficult to do a regular publish, put everything into a zip file, send that, then have your users decompress the zip and run your app from there.
maria 🌟
maria πŸŒŸβ€’17mo ago
not the same :c
Thinker
Thinkerβ€’17mo ago
It's either a single massive exe file, or a folder with one exe and at least one DLL. Pick one.
maria 🌟
maria πŸŒŸβ€’17mo ago
there must be another way
Thinker
Thinkerβ€’17mo ago
Again, if you do this, you'll get only two rather small files: an exe and a DLL, which still requires the user to have the .NET runtime installed.
maria 🌟
maria πŸŒŸβ€’17mo ago
on net 7 where are the packages saved?
Thinker
Thinkerβ€’17mo ago
~/.nuget is the Nuget cache afaik
maria 🌟
maria πŸŒŸβ€’17mo ago
?
Thinker
Thinkerβ€’17mo ago
I think the .NET libraries are downloaded somewhere to your appdata or something, but I'm unsure of where Nuget packages go
maria 🌟
maria πŸŒŸβ€’17mo ago
why they arent saved on proyect to prevent duplication of packages on diferent proyects?
Thinker
Thinkerβ€’17mo ago
probably But again, if you publish an app the regular way, it'll just dump all the DLLs in the output folder
Landan
Landanβ€’17mo ago
I used chatgpt to create a bash script to pipe tar archives without persisting them on the filesystem, and then grabbed the artifact I wanted out of it. Maybe you could try that (I dont have the code available to me atm)
maria 🌟
maria πŸŒŸβ€’17mo ago
and for windows
teauxfu
teauxfuβ€’17mo ago
I dunno your use case, and this doesn't answer your question, but... why not just use an installer? if you know the users will already have .NET runtime, then doing framework-dependent single-file is probably your best bet. https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?source=recommendations&tabs=cli
Create a single file for application deployment - .NET
Learn what single file application is and why you should consider using this application deployment model.
maria 🌟
maria πŸŒŸβ€’17mo ago
yes thath or just create another program on framework thath loads the dll from memmory like reflective injection
teauxfu
teauxfuβ€’17mo ago
second option sounds bad, if you're going to introduce a 2nd program it may as well just be the installer
WhiteBlackGoose
WhiteBlackGooseβ€’17mo ago
I have a secret technique protecting against decompilation of your project (but others are gonna eat me for suggesting that) @Gato I made a cheatsheet for NAOT https://wbg.gg/misc/naot/ you can try those commands they return one single smol executable file (but you need to test it to ensure it works)
Thinker
Thinkerβ€’17mo ago
notably Native AOT breaks reflection and some other things
maria 🌟
maria πŸŒŸβ€’17mo ago
Determining projects to restore...
All projects are updated for restoration.
C:\Program Files\dotnet\sdk\7.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(231,5): error NETSDK1175: Windows Forms is not supported or recommended with cropping option enabled. For more information, go to https://aka.ms/dotnet-illink/windows-forms
Determining projects to restore...
All projects are updated for restoration.
C:\Program Files\dotnet\sdk\7.0.200\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(231,5): error NETSDK1175: Windows Forms is not supported or recommended with cropping option enabled. For more information, go to https://aka.ms/dotnet-illink/windows-forms
Angius
Angiusβ€’17mo ago
Winforms being Winforms I see
maria 🌟
maria πŸŒŸβ€’17mo ago
but winform is ez 😭 and without begin design expert you can do decent beautifully things
Angius
Angiusβ€’17mo ago
>beautiful >winforms Pick one lol
maria 🌟
maria πŸŒŸβ€’17mo ago
beautiful?
Angius
Angiusβ€’17mo ago
I'm not familiar with the word biutifil so I assumed you misspelled beautiful or beautifully
maria 🌟
maria πŸŒŸβ€’17mo ago
yes mb
Angius
Angiusβ€’17mo ago
Ah, you were making your choice lol I misunderstood, sorry
Thinker
Thinkerβ€’17mo ago
If you wanna make beautiful apps, or at least apps with a decent degree of visual customization, then WinForms is absolutely awful WPF or Avelonia allows much more freedom
Accord
Accordβ€’17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
maria 🌟
maria πŸŒŸβ€’17mo ago
no is not
Thinker
Thinkerβ€’17mo ago
tl;dr Native AOT doesn't support WinForms, and the other options have already been discussed. there's no way to get only the exe without at least one DLL.
Dusty
Dustyβ€’17mo ago
I actually know how to fix this Let me check sec
Dusty
Dustyβ€’17mo ago
How to: Generate Interop Assemblies from Type Libraries - .NET Fram...
Generate interop assemblies from type libraries. Use Type Library Importer (Tlbimp.exe) to convert coclasses and interfaces from a COM type library to metadata.
Dusty
Dustyβ€’17mo ago
You can generate your own .NET DLL from your C++/native library And then you can include it via
<ItemGroup>
<Reference Include="WUApiLib" />
</ItemGroup>
<ItemGroup>
<Reference Include="WUApiLib" />
</ItemGroup>
in your .csproj file. Replace WUApiLib with your managed (.NET) DLL file name that you generated using the tool linked above. That way you don't have any comreferences in your project and can use the full functionality of the dotnet cli
maria 🌟
maria πŸŒŸβ€’17mo ago
I dont use thath anymore i just want a single light weight exe and if its posible every time i compile
Dusty
Dustyβ€’17mo ago
oh okay
Accord
Accordβ€’17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
maria 🌟
maria πŸŒŸβ€’17mo ago
i dont care if i loose support to linxu or other os
Thinker
Thinkerβ€’17mo ago
Just publish self-contained, zip up the files, give that zip to your users, then they just have to unzip it and run the exe. Simple.
Accord
Accordβ€’17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.