I'm working on a legacy C# ASP.net WebForms project.
When it's published, the wwwroot folder contains the .aspx and .aspx.cs files for each page. I need the site to be precompiled using .dll's for each page in the Bin folder.
What is the setting in Visual Studio to publish the website with precompiled dlls and no .aspx.cs files?
In the Property Pages → MSBUild Options I have unchecked the option
- ☐Allow this precompiled site to the updatable
but this has not done anything.
The "type" of project will determine this ability to publish with having all the source code stripped out and only the aspx pages + compiled .dll's.
So, (unfortunately) there is not some "setting" but that of the project type chosen that determines if you have such a publish option.
If you have a "asp.net web site" as opposed to a "asp.net web site application", then a web site does not have such an option during publish. (ie: you still will always be including source code files).
So, a with a "web site", then you are NOT supposed to use nor open such projects using a .sln project file, but you are to use
File->open web site.
So, ONLY the web site "application" option gives you the option to strip out source code files, and pre-compile. In fact, this ability has several advantages over that of a "web site", and of course that of pre-compiling the site before you publish is one such advantage. I believe that a web site publish also has an option to "force" or "pre-compile", but that option WILL STILL result in both the source code files (aspx.cs, or aspx.vb) pages being published anyway. In other words, you can choose ALL the pre-compile options on planet earth, but while that might pre-compile the .dll's, this does NOT prevent the including of the source code files during a publish.
The reason is of course such projects STILL allow you to update one .aspx page, or one .aspx.cs page (source code) and simply copy to the web server. So, pre-compile options might speed up the first time the web site runs, but to be 100% clear this does NOT change the project type, nor prevent the source code files being copied to the server. So, pre-compile options are VAST different in a web site, and those options don't prevent the source code files being published, and such options don't prevent 100's and 100's of .dll's being created for such sites.
Of course, the big advantage of this "web site" option is that you can make changes to one .aspx page, or changes to the code behind, and then ONLY have to publish (or copy) the 2 pages to the target site and server, and you are done. This of course means that IIS is now doing the compile of your code and site, but MORE of a concern is that means Visual Studio is no longer doing the .dll and assembly resolution(s) for you. And a web site also does not allow multiple projects to be included for the build process. And perhaps worse is that your NuGet packages and referenced .dlls DURING development have to reside in the bin folder. You thus can't delete the bin folder and re-compile. And where I come from, when writing software, the concept of a build process producing the final and correct .dll's output is a 100% requirement.
So, is there a solution?
Well, you could re-factor the site to become an "application". Part of the process is in fact "automated".
I can't find the "convert" to application in vs2019, or vs2022, but it supposed to exist.
The steps to convert from web site to web site application? It is a bit involved, since "applications" now have a "designer" file and "web sites" do NOT have nor use designer files. (the designer files thus again enforce FAR MORE strict compile time resolutions here).
The steps to convert such projects is outlined here:
https://devblogs.microsoft.com/dotnet/converting-a-web-site-project-to-a-web-application-project/
It you attempt the above, of course work on a copy of the project.