C
C#β€’2y ago
maria 🌟

❔ Net 7 How to output one exe without dlls

Halp $singlefile didnt worked
117 Replies
MODiX
MODiXβ€’2y 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 🌟OPβ€’2y ago
and the exe doenst run without the dll sooo
Thinker
Thinkerβ€’2y ago
what did you try?
maria 🌟
maria 🌟OPβ€’2y ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true
Thinker
Thinkerβ€’2y ago
you have to replace <runtime identifier> with a... runtime identifier
maria 🌟
maria 🌟OPβ€’2y ago
yes i did
Thinker
Thinkerβ€’2y ago
translate plz
maria 🌟
maria 🌟OPβ€’2y ago
done
Thinker
Thinkerβ€’2y ago
Try adding --self-contained
maria 🌟
maria 🌟OPβ€’2y ago
Task "ResolveComReference" is not supported on .NET Core version of MSBuild. Use the MSBuild version of the .NET Framework. See
Thinker
Thinkerβ€’2y ago
yeah idk what that's about :/
maria 🌟
maria 🌟OPβ€’2y ago
thaths because i have windows media player on proyect?
Angius
Angiusβ€’2y ago
For context: the project was migrated from Fx 4.8 to .NET 7 using the Upgrade Assistant ( #❔ nul )
Thinker
Thinkerβ€’2y ago
ah
maria 🌟
maria 🌟OPβ€’2y 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β€’2y ago
maria 🌟
maria 🌟OPβ€’2y ago
oh -c release
Thinker
Thinkerβ€’2y ago
maria 🌟
maria 🌟OPβ€’2y ago
Doenst work :C
maria 🌟
maria 🌟OPβ€’2y 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β€’2y ago
have you tried dotnet publish -c Release -r <rid> --self-contained -p:PublishSingleFile=true? Also can you show your csproj file?
maria 🌟
maria 🌟OPβ€’2y ago
thath i was gonna do because i was modifyng it befotre
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
sry
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
yes but i need it for the music
Thinker
Thinkerβ€’2y ago
<Exec Command="Obfuscar.Console.exe config.xml" />
are you... running an obfuscator
maria 🌟
maria 🌟OPβ€’2y ago
yes 😭
Thinker
Thinkerβ€’2y ago
well you can get rid of that
maria 🌟
maria 🌟OPβ€’2y ago
why
Thinker
Thinkerβ€’2y ago
obfuscation in .NET is literally useless
maria 🌟
maria 🌟OPβ€’2y ago
hmm on framework works
Thinker
Thinkerβ€’2y ago
yeah, the error message above says that COMReference isn't a thing you can use with modern versions of .NET
maria 🌟
maria 🌟OPβ€’2y ago
you can steale whole proyect with a single decompiler
Thinker
Thinkerβ€’2y ago
yep
maria 🌟
maria 🌟OPβ€’2y ago
thaths because i use it then
Thinker
Thinkerβ€’2y 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β€’2y ago
$obfuscation
MODiX
MODiXβ€’2y 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 🌟OPβ€’2y ago
ok so i cant use windows media player yea i nkow
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
Naudio?
maria 🌟
maria 🌟OPβ€’2y ago
thaths what i said yes
Thinker
Thinkerβ€’2y ago
(that specific tutorial)
maria 🌟
maria 🌟OPβ€’2y 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β€’2y ago
well, every time you want to publish your app
maria 🌟
maria 🌟OPβ€’2y ago
but just i want to compile in just one file
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
now i got another error
Thinker
Thinkerβ€’2y ago
--self-contained
maria 🌟
maria 🌟OPβ€’2y 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β€’2y 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 🌟OPβ€’2y ago
on framework and costura fody was 2 mb .... a couple
maria 🌟
maria 🌟OPβ€’2y ago
i got this error
maria 🌟
maria 🌟OPβ€’2y ago
i cant start thath on framework worked
Thinker
Thinkerβ€’2y ago
afaik you have to use the Powershell setting for Process to be able to start URLs
maria 🌟
maria 🌟OPβ€’2y ago
what
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
process start doenst have use shell executed enabled by default?
Thinker
Thinkerβ€’2y ago
apparently not
maria 🌟
maria 🌟OPβ€’2y ago
but on framework yes 😭
Thinker
Thinkerβ€’2y ago
idk Framework is weird
maria 🌟
maria 🌟OPβ€’2y 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β€’2y ago
well, .NET libraries are essentially the same as Nuget dependencies They're all just... DLLs
maria 🌟
maria 🌟OPβ€’2y ago
but are alredy installed on computer
Thinker
Thinkerβ€’2y ago
What is?
maria 🌟
maria 🌟OPβ€’2y ago
yes like framework is alredy installed on windows
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y 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β€’2y ago
Then you can get rid of the -p:PublishSingleFile=true thing
maria 🌟
maria 🌟OPβ€’2y ago
but i just want the exe and the dll in a single file
Thinker
Thinkerβ€’2y ago
hold on
maria 🌟
maria 🌟OPβ€’2y ago
just theese 2
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
i just want the exe
Thinker
Thinkerβ€’2y ago
So you want the exe, but not any libraries packed into it?
maria 🌟
maria 🌟OPβ€’2y 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β€’2y 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 🌟OPβ€’2y ago
not the same :c
Thinker
Thinkerβ€’2y ago
It's either a single massive exe file, or a folder with one exe and at least one DLL. Pick one.
maria 🌟
maria 🌟OPβ€’2y ago
there must be another way
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
on net 7 where are the packages saved?
Thinker
Thinkerβ€’2y ago
~/.nuget is the Nuget cache afaik
maria 🌟
maria 🌟OPβ€’2y ago
?
Thinker
Thinkerβ€’2y 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 🌟OPβ€’2y ago
why they arent saved on proyect to prevent duplication of packages on diferent proyects?
Thinker
Thinkerβ€’2y 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β€’2y 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 🌟OPβ€’2y ago
and for windows
teauxfu
teauxfuβ€’2y 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 🌟OPβ€’2y ago
yes thath or just create another program on framework thath loads the dll from memmory like reflective injection
teauxfu
teauxfuβ€’2y ago
second option sounds bad, if you're going to introduce a 2nd program it may as well just be the installer
WhiteBlackGoose
WhiteBlackGooseβ€’2y 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β€’2y ago
notably Native AOT breaks reflection and some other things
maria 🌟
maria 🌟OPβ€’2y 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β€’2y ago
Winforms being Winforms I see
maria 🌟
maria 🌟OPβ€’2y ago
but winform is ez 😭 and without begin design expert you can do decent beautifully things
Angius
Angiusβ€’2y ago
>beautiful >winforms Pick one lol
maria 🌟
maria 🌟OPβ€’2y ago
beautiful?
Angius
Angiusβ€’2y ago
I'm not familiar with the word biutifil so I assumed you misspelled beautiful or beautifully
maria 🌟
maria 🌟OPβ€’2y ago
yes mb
Angius
Angiusβ€’2y ago
Ah, you were making your choice lol I misunderstood, sorry
Thinker
Thinkerβ€’2y 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β€’2y 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 🌟OPβ€’2y ago
no is not
Thinker
Thinkerβ€’2y 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β€’2y ago
I actually know how to fix this Let me check sec
Dusty
Dustyβ€’2y 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β€’2y 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 🌟OPβ€’2y ago
I dont use thath anymore i just want a single light weight exe and if its posible every time i compile
Dusty
Dustyβ€’2y ago
oh okay
Accord
Accordβ€’2y 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 🌟OPβ€’2y ago
i dont care if i loose support to linxu or other os
Thinker
Thinkerβ€’2y 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β€’2y 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.
Want results from more Discord servers?
Add your server