question

MarkGreen-2360 avatar image
0 Votes"
MarkGreen-2360 asked MarkGreen-2360 answered

Visual Studio 19 apps are much larger and include .dll files

After previously using Visual Studio 2015 and 2012, I recently installed and began using Visual Studio 2019. Right away I noticed that .exe files, even for small apps were large, e.g. 150-200 KB. Using VS 2012, much larger apps had .exe sizes of 20-30 KB. I also noticed that apps developed with VS 2019 have .dll files. Apps developed using previous versions of VS do not.

Nearly all of the apps I develop are created using the Windows Forms Desktop template. They are meant to be simple apps that run on a Windows PC. Is there a simplified template that I can choose when I create a new project in VS 2019 so that apps are smaller and no .dll files are necessary?

vs-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

cooldadtx avatar image
0 Votes"
cooldadtx answered

Which template are you using exactly - there are multiple winforms templates? If you're targeting .NET Core/5 then yes there will be lots of extra DLLs because the runtime is very small so all additional dependencies are included in the app. This helps prevent breaking changes when the runtime is updated at the cost of more space.

However if you're building a .NET Framework application then nothing has changed. The monolithic runtime is already installed somewhere and your app just needs its own code. Of course if an update to the .NET Framework happens to break your app there is not much you can do about it as the runtime is shared and you have no control over the runtime installed on a client machine but your app is smaller.

This is the standard tradeoff that all languages/platforms have. Note that if you are building a .NET Core/5 app and you don't want any dependencies on external code then you can use a self contained deployment which packages everything into one. This makes it easier to deploy but the binary will be bigger and it is not cross-platform IIRC. The docs provide some guidance here.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MarkGreen-2360 avatar image
0 Votes"
MarkGreen-2360 answered cooldadtx commented

I'm using one of these two circled templates (see attached screenshot). I used a text editor to look in some of the files in a solution/project but couldn't tell which template was used to create it.
87410-vs-2019-project-templates.jpg

From your description, it sounds like a Windows Forms app using the .NET Framework is what I want in order to have a smaller app. If I wanted to re-create my existing Windows Forms app as a .NET Framework app, how would I do that? Could I just create a new Windows Forms project using .NET Framework and then add the Form1.cs and Form1.Designer.cs files to the new project?

Thanks!



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Right click the project and select Properties. Go to the Application tab if not already there. The Target framework tells you which one.

If it is .NET Core/5 then you cannot switch to .NET Framework from the UI. Close Visual Studio. Open the project file (.csproj) in a text editor. Find the TargetFramework property in the XML. It should be one of the first lines. Change its value from netcore?? or net5.0 to net472. Save and close the file. Open the solution up in Visual Studio and it should switch over to .NET Framework. Rebuild to verify everything works.

0 Votes 0 ·
MarkGreen-2360 avatar image
0 Votes"
MarkGreen-2360 answered

Thank you very much! My project was based on .NET Core 3.1 which explains its large size and .dll's.

I checked a second project that I created recently using VS 2019 and it was based on .NET Framework 4.7.2. The .exe file was quite small and there were no .dll's.

It makes sense now. Thank you for explaining the difference so that I can convert my existing project and choose the right template for new projects.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.