aspnet_compiler -fixednames does not work? - c#

I am unable to get the -fixednames switch to create dlls for the cs code behind files. The files in the bin folder are compiled aspx pages, but the code behind files are all compiled into one large websitename.dll file.
Here is my command with switches.
aspnet_compiler -v / -p E:\Source\DotNet4\mysolution\website -f -d -fixednames E:\Source\DotNet4\CompiledWebSite
This produces many files in the bin folder.
website.dll and website.pdb (contains code behind)
myform1.aspx.643c7876.dll (compiled aspx layout ui)
I have tested this over and over to make sure I am not missing anything. The test is place a label on myform1.aspx, and in the codebehind populate the label with some text. Compile the website with the above switches and deploy the website.
Make a change to the myform1 codebehind and change the label text. Compile and only deploy the myform1.aspx.643c7876.dll to the website. Result: label is still the same. Now deploy the website.dll and pdb and the label changes.
Can anyone tell me how to get -fixednames to create sinle dlls for codebehind?

I think the difference really is in the Web Application vs. Web Site concept. I created two identical apps - one as a Web Application, and one as a Web Site, in Visual Studio. The page was default.aspx, and the class is "_Default". When I ran "aspnet_compiler -v / -p . -f -d -fixednames ..\CompiledSite" on the Web Application, there were 2 dlls in the new bin, one called WebApplication1.dll, and it contained the _Default class, and one called App_Web_default.aspx.cdcab7d2.dll, which contained the markup. When I compiled the WebSite with the exact same command line, it only created one DLL, with both the markup and the _Default class.
Don't ask me how it knew the difference between the two - the only thing I can think of is the fact that the csproj file exists for the Web Application.
From what I've read and the way I understood things, aspnet_compiler was designed for WebSite projects, not Web Application projects, which is why I assumed you were using a WebSite.
If you need your application designed to be single-paged DLLs, try building a new WebSite project, adding your .aspx and .aspx.cs files to that WebSite, and compiling with your aspnet_compiler command, and see what happens. You can start with just one or two pages for a sample.
You won't need to actually test and recompile etc. in order to determine if it worked - just look at the DLL files in Reflector, and see where your classes live - if they live in the same DLL as the markup, then it worked, otherwise, they must be in the centralized application DLL.
Hopefully that all made sense - good luck.

Related

How can I precompile assemblies?

I'm new to ASP.NET, and making a small update to a site that already exists. I am confused about the differences I see on the production server vs. the source code I've been given, and would appreciate any explanation or advice. Normally I would just continue reading and researching until I understood fully, but in this case I've been asked to make a small update to something ahead of my understanding. All I need to do is change one element in a form.
On the production site, there are files like \contact\survey.aspx; no .cs files exist in the directory alongside them, and there's no CodeFile directive. Instead, there are a multitude of DLL files corresponding to these pages, like bin\App_Web_survey.aspx.fdf9difs9.dll.
When I was given the source code of the site to edit, I see something different. The bin folder is entirely lacking in these DLL files corresponding to pages; instead, each aspx file has an aspx.cs file sitting next to it in its folder, a code-behind. Fair enough, I think; the site can run in its interpreted mode, like this, or compiled to DLLs.
Problem is, for the life of me I cannot work out how to do that; I've read dozens of pages on the MSDN library and gotten nowhere.
I am using Visual Studio Express 2013 for Web, and I've opened the source code folder as a website. When I run 'build', it succeeds, but no DLLs are made, not even in the Debug folder. This MSDN page has instructions for compiling web application projects, but the options don't correspond to the available options for me, so I'm guessing that either web application and web site are distinguished or that Visual Studio 2013 (which I also tried using and had no luck with) is distinguished from VS for Web. I'm at a loss.
tldr: Can anyone quickly sum up for me the process of compiling an ASP.NET website in a way that results in multiple DLL files in its bin directory?
You might need to use aspnet_compiler:
aspnet_compiler -p sourceCodeRoot -v / targetRoot
See How to: Precompile ASP.NET Web Sites for Deployment (MSDN).

Can I compile a single aspx.cs file into a DLL?

I'm attempting to make a single small update to a website written in C#/ASP.NET.
All I'm trying to do is change the email address a form submits to, which is why I'm not seeking out a proper C#/ASP.NET developer.
I've done a little research, and it seems that the site itself is using dll files in the /bin folder to run the forms and things. The form is contact.aspx.f3293f9sd.dll, so I've edited the corresponding contact.aspx.cs file.
What do I do now?
Can I build this single CS file into a single DLL and upload it? I've scoured the menus and see no such option, and Google results seems to imply that you need to add entire projects and build entire projects at once.
Is that correct? What's the process here?
What you need to do is open the solution file. Solution files are files composed of projects. The contact.aspx.cs file is part of one of those projects. You need to make your change in the file, then recompile your solution. Then you can upload the DLL file it outputs to your production. Make sure you compile in Release mode.

Website compilation process[AppCode DLLs]

We are working on a website project which contains around 1130 pages. After compilation, all the .aspx.cs files are converted into AppCode DLLs that has random names.
Whenever there are any changes in single .aspx.cs file[like a hotfix], we have to recompile and deploy the entire project on the application host.
We want to update only those files that have been changed and not the entire package.
One of a solution we are aware is that, converting Website to Web application; but we cannot implement that change at this stage of the project.
Is there any other way to find an efficient solution for this?
Yup. Talking in Visual Studio 2010:
While publishing the website, Select the option: 'Use Fixed naming and single page assemblies', Also select 'Allow this precompiled site to be updateable'.
After website is published. Go to the published folder. Open any aspx page (not the dll or .cs).. Note the dll name in page attribute under inherits attribute. Than using ftp or any other way to upload, copy or upload tht dll under bin to your website.
Also, you can create a doc or txt file to list all Dll names with respective paths to your file to easily know which dll to upload next time if there is any change.
Hope it helps.

In an ASP.NET website with a codebehind at what point are the .cs files compiled?

In Brief:
In an ASP.net website with a code-behind, at what point are the *.cs files compiled?
Context:
A colleague who has since left, deployed a website with a .cs code-behind to a shared server. I have made a small change to a .cs file, which I should expect to reflect on one of the pages but it has not yet appeared. I have restarted the application pool, however I am loathe to reset IIS on the server as there are couple of other teams' apps which might be be in use on the same server.
This applies to Web Application projects as opposed to Web Site projects, which are CodeFile by default, and don't allow changing the build action...
In ASP.NET Web Applications you have two methods of deploying your pages; CodeFile and CodeBehind. By default pages will always use CodeBehind but you can change this.
CodeBehind
CodeBehind compiles your .cs file into the .dll file in your bin folder at compile/build time, and then you deploy that to your web server. There is no need to deploy the .cs file to your web server. If you do, it will just sit there being unused.
To configure a page with CodeBehind, ensure that:
The page directive in your .aspx file has CodeBehind="your.aspx.cs"
The properties of the .cs and .designer.cs files in solution explorer have a build-action of compile.
CodeFile
This causes ASP.NET to compile the .cs file on-the-fly on the server. This means that your .cs file needs to be deployed to the web server. It also means that your .cs file will not be compiled at compile/build time and therefore not built into your .dll in the bin folder.
Key advantage
With CodeFile, You can make changes to the .cs file and deploy just that file to see the changes on your production web server. No need to re-deploy. No need to recycle the app pool. This can be very useful in a lot of situations.
To configure a page with CodeFile, ensure that all of the following are met:
The page directive in your .aspx file has CodeFile="your.aspx.cs"
The properties of the .cs file in solution explorer have a build-action of content
The properties of the .designer.cs file in solution explorer have a build-action of none.
Notes
Intellisense doesn't like working when pages are set up with
CodeFile (you can change to CodeBehind whilst coding and then change back for deployment, though).
If you change from CodeBehind to CodeFile, then always do a
rebuild and re-deploy (and vice versa). This is because when the page was CodeBehind,
the .cs was compiled into the .dll in the bin folder, and will
remain there when you change to CodeFile. The CodeFile will be
compiled on-the-fly and you will get the same code/classes defined in
the .dll and in the on-the-fly compiled code, which will lead to
runtime errors.
For the setup I use, the .cs files are compiled when building the project. This means it is the .dlls in the bin that need to change, not the .cs files directly.
The .aspx files can change at any time, but I think you need to rebuild the project in order for the code behind to take effect.
I have replaced singular .dlls before without any problem (though it's not good practice).
Apparently what you have done should work.
Check if Cacheing has been implemented.
Otherwise publish the code and deploy the dll, instead of .cs file. I would recommend to test in staging server before you go live.

Compile LESS, minify CSS and JS and output to build directory

So, I recently started with ASP MVC4 and on my journey I discovered several new technologies and frameworks, such as LESS, Bootrap etc. (because I haven't done any web application in years!) whose capabilities completely blew my mind. I worked my way through various tutorials and the only thing I learnt is: How bad they work together. I just can't get anything working and its extremely frustrating.
What I want to achieve:
Having bootraps less source along with other site specific less files in one directory, such as Content\style\less\*.less (also for JS files: Scripts\*.js)
Compile LESS files at build (pre-build)
Copy all files to custom build directory, e.g. bin\style\*.css
Minimize and optimize css and js files in output directory.
Bundle all together at runtime
What I fail at:
Copy ALL files to custom build directory. Visual Studio just compiles the code and copies it to bin\
Compile less files properly. I created a pre-build instruction with the dotless.compiler.exe, but it fails at simple tasks, such as copying to new directory or reverse directory compiling (when I say compile \Content\style\less\*.less it just compiles every file in this directory, not in directories below.
Optimization and minify: It seems that the Web.Optimization bundling instruction only work at runtime, not at build time!
I hope anyone can help me.
Technologies and frameworks I used: ASPX, MVC4, Razor, dotless, Bootstrap, Web.Optimization
Edit: Regards the output task: Am I expecting too much? Compiling an application and copy every necessary resource to a seperate \bin (build) directory is a common element in .NET application production lifecycle for ever. Why not for ASP sites, since they are called applications aswell.
After installing Web Essentials, Shift+Alt+Y is the default keybinding for triggering a recompile of all .less-files.

Categories