I'm migrating from .NET Framework to .NET (Core).
I've just realized that .NET Core applications created by VS2022 always have a DLL:
And if I examine my EXE's details:
Why is the original filename set to the DLL? Can I change it to WinFormsApp2.exe?
With .NET Framework, no DLL was generated, and original filename was always set to the current EXE file. Can I reach this with .NET (Core) too?
.net core applications are cross-platforms which is why DLL is generated as part of the build process. DLL contains the compiled so you can run the app on platform which have .net core runtime.
you can change the setting in visual studio for a different DLL name.
on the other hand,.net framework applications are built as single executable file (EXE) that contains all the application's code and dependencies which is to be run only on windows OS.
It is normal to have .dll extension file because it is library which contains your code and allows to run program for multiple time in windows.
Related
Hey I switched from NET Framework 4.8 to .NET 6.0
When I build my file it outputs the build.exe (130kb) and an build.dll (2.3mb).
So it looks like the exe is using the dll to run as the dll has the source code inside and the .exe doesn't.
Is it possible to build an .exe only without the dll?
I tried to use a Costura Fody an resource embedder but that didn't work.
Edit:
I was able to use the "publish" feature to create a self contained exe but the file size increased from 3mb to an 180mb exe... Is there any other method?
You probably want a single file framework dependent deployment and not "self contained". This way you would not have to include all the framework file in your deployment package, instead the computer would have to have the framework already installed. To do this, change deployment mode in the deployment settings from self contained to framework dependent. See Single file deployment
You might also check out "trimming" to remove unneeded dependencies, since this should significantly reduce the size of a self contained application.
Your observation is right.
The .exe file of a .NET core app is only a stub loader. The actual code is in the .dll file. For the application project, you now have both an application.dll and an application.exe.
Unless you use any of the options you mentioned (deploy as single file), I don't think there's a way around this.
When i build my .NET Core Console Application using .NET Core 3.1 sdk,it generates both .exe as well as .dll as output. When i was using .NET Core 2.1 it was generating only .dll as output. Is there a way to restrict .NET Core 3.1 sdk to generate only .dll as output?
You can control this with the UseAppHost MSBuild setting:
The UseAppHost property was introduced in the 2.1.400 version of the .NET Core SDK. It controls whether or not a native executable is created for a deployment. A native executable is required for self-contained deployments.
In .NET Core 3.0 and later versions, a framework-dependent executable is created by default. Set the UseAppHost property to false to disable generation of the executable.
<PropertyGroup>
<UseAppHost>false</UseAppHost>
</PropertyGroup>
If you want to disable this when building from the command line, instead of setting it within the .csproj, pass the property as an argument. For example:
dotnet build /p:UseAppHost=false
In .NET, the difference between a .exe and a .dll is actually very small. .exe tend to be little more then .dll's with some bootstrap code and a start point (the class whose main method is to be called).
You can use both .NET .exe and .dll as project references. There might be some difference in some fringe details like COM interop, but I do not expect it.
What exactly the compiler will build, depends on it's inputs. Wich includes the project settings. There is a special type of project for library. And with version changes, the proper reading of projects files could be broken. And of course the option that some code is "seperated out" into a .dll is also there. Most programms nowadays are more .dll's then executeables. And it can be beneficial to keep .exe small.
Is there a possibility to publish .NET Core Console Application as single file (no matter if it's EXE or DLL)?
I am using .NET Core 1.1 but I am elastic to port my project to another version.
At the moment, this is not possible because:
portable applications still need at least a runtimeconfig.json to tell the host (dotnet / dotnet.exe) which shared runtime to use. Even if you IL-Merge all your managed code into a single dll, this file is still required. The host also expects a deps.json expressing the dependencies of the application.
self-contained applications rely on building a .dll + .deps.json and copying over content from runtime-specific NuGet packages. This also includes native libraries that are searched for by file name.
The CoreRT project aims to compile a .NET Core application to a single native binary using ahead-of-time compilation but is still in development.
I'm a newbie to Roslyn compiler services, I would like to create an .exe with .net full or .net core which can call Roslyn API, that program must run on a machine that does not have installed Visual Studio, I just want to distribute (copy/paste) the .exe and it should work.
I have no idea what programs must be installed on that machine to my .exe can work properly (making calls to Roslyn API).
Can it run only with .net framework installed?
Most of Roslyn is just a library, so if you build a project that references the Roslyn NuGet packages, it will compile into a directory of files that are all you need to run the application (assuming you have the appropriate version of .Net Framework or .Net Core installed).
If you really want just a single EXE file, you will need a tool that combines an application and its dependencies into a single file, like ILMerge.
I'm trying develop a sample application with multi language files.
I use: Windows 7 64bit and Visual Studio 2012 Express.
I read a few tutorials on the web, and I created a sample app.
In my Debug directory I created folders for language files: 'en' and 'pl'
I created text resource files in these directories and in the main directory, so my file structure is:
lang.txt
lang.resouces
multilang.resources.dll
multilang.exe
-en
--lang.en.txt
--lang.en.resources
--multilang.resources.dll
-pl
--lang.pl.txt
--lang.pl.resources
--multilang.resources.dll
I wrote a .bat file to embed satellite assemblies do my app
resgen lang.txt
al.exe /t:lib /embed:lang.resources /culture:pl-PL /out:multilang.resources.dll
resgen en/lang.en.txt
al.exe /t:lib /embed:en/lang.en.resources,multilang.en.resources /culture:en /out:en/multilang.resources.dll
resgen pl/lang.pl.txt
al.exe /t:lib /embed:pl/lang.pl.resources,multilang.pl.resources /culture:pl /out:pl/multilang.resources.dll
In my application I use ResourceManager
_rm = new ResourceManager("multilang", Assembly.GetExecutingAssembly());
and the GetString method to obtain text
this._rm.GetString(stringFromRm);
It works fine when I compile my App in the .NET 4.5 Framework, but when I change the Target framework in Project properties to .NET 2.0 I always get this exception:
System.Resources.MissingManifestResourceException
My app must work on Windows XP, so it must work with earlier .NET Framework versions.
Could somebody tell me what I must change to run my app on .NET Framework 2.0 ?
When running resgen.exe or al.exe for an application that should run on .NET framework, you must make sure that generated assemblies can be read by .NET 2.0 runtime. Assembly format has been extended in .NET 4, so the 2.0 runtime is to able to load 4.0 assemblies.
So make sure that you're using both tools from C:\Windows\Microsoft.NET\Framework\v2.0.50727 and not from a newer framework version.