12

I have noticed that both dll and exe files with the name of the project are created on Windows when compiling a .NET Core console application. Why is that? In full .Net framework only the exe file would be created.

mark
  • 59,016
  • 79
  • 296
  • 580

1 Answers1

12

Prior to .Net Core 3.0, only the dll was created (although you could still do a single file build that was platform-dependent). In these cases you had to use the command dotnet MyProject.dll to start your program.

With .Net Core 3.0, they added the exe, which is still really just a wrapper around the command above. On other operating systems it also creates an executable file, it just names it MyProject instead of MyProject.exe

If people have old scripts that still make the dotnet command, this setup doesn't break them, but if you want to just use an exe, you can do that too.

pquest
  • 3,151
  • 3
  • 27
  • 40
  • 1
    Is there a place in the official documentation that describes this behaviour? – mark Apr 09 '20 at 01:08
  • @mark I think this is probably what you are after https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0#compiledeploy – pquest Apr 09 '20 at 01:16
  • Maybe you can answer https://stackoverflow.com/questions/61112507/how-to-suppress-creating-of-the-platform-specific-executable-when-building-a-ne ? – mark Apr 09 '20 at 01:21
  • @mark for .net core you can actually place all the package metadata in the csproj file rather than creating a separate nuspec file. You can then use the dotnet pack command to generate a package. Additionally you can set the property in the csproj to Library. That will remove the exe. Lastly, you probably don't need to target netcoreappx.y for a nuget package. It is actually better to target netstandard2.0 or netstandard2.1 because then your package will work with any compliant framework. https://learn.microsoft.com/en-us/dotnet/standard/net-standard – pquest Apr 09 '20 at 18:45