asp.net single file publish - asp.net

i have publish my website. using publish website in vs 2008.
Now i want to update a single file.
So do i need to recompile the whole web-site and upload it to the server again, or i will just publish this single file and upload it to the server.
if i can compile a single file then how to do it, also how to update it to the server?

Depends on whether your web project is a web application project or web site project. If its a web site, then you can just copy your updated file to the server and ASP.NET will recompile it for you.
If your web project is a web application project, and you made changes to the code behind, you'll need to recompile the project, and redeploy the DLL.
Also, if you're just updating an ASPX page (not the code behind, ASPX.cs), you should be able to deploy it without compiling.

If you frequently update your website, I recommend to Check
Use fixed naming and single page assemblies checkbox.
This will generate seperate DLL for each code behind page,
Although you have to compile full project but you can upload only relevant file.
This is very helpful in case if many people are working in single project, everybody can change in their respective .cs file and publish their .cs file's DLL , this will not affect other people's DLL and thus functionlity will not break, unless DLL's or codebehind clashes with each other.

Related

Remove .cs file in published asp.net webforms project

In the old asp.net project, there is a published .cs file in one of the folders. When I update the site, I update the .dll files, but this file is never updated. When I delete this .cs, the site does not work. How do I delete this file?
Are you using a asp.net web site applcation to publish, or are you using a asp.net web site?
As a general rule, if you using asp.net web site applcation, then the source code files are NOT required to be up-loaded.
However, you left out one big detail. Where is that cs file? While a asp.net web site will attempt and does pre-compile all code, ONE BIG exception to this rule exists.
That is the folder app_code. That folder is in fact compiled by IIS, and as a result, if that file is in that folder, it will have to be included in your publish.
In fact, when I started using the newer Roslyn compiler (I liked it VERY much for allowing me to have longer free text such as SQL in the code as strings).
However, IIS did not and does not have Roslyn compile by default. And my code was breaking.
So, as a result, I simple create my own folder called MyCode. And you could do the same. Note that each code module (vb.net) or static class for your general shared code routines do have to be marked manually as to compile.
eg this:
So, if your .cs file is in app_code, then you can move it out, drop it into a folder you create, and set the file build action to compile, and of course do not copy.
However, and this is a HUGE big "if". If your deployment model is web site as opposed to web site applcation, then this will not work, since IIS is doing your compile after deployment, as opposed to pre-compiling the code BEFORE deployment.
So, you are in luck if your .cs file is (or was) in app_code, since then as noted, you can move that out of app_code, and in properties set the file to be compiled, but not deployed. This as noted will only work if you deploying as a asp.net web site applcation as opposed to a asp.net web site.

Update pre-compiled files in ASP.NET

After publishing asp.net web site, I got mant ASP_Web_xxxxx.dll.
After deploying these files to production server, how do I know which file to be replaced, if I modify one codebehind or .aspx file and re-publishing the web site?
Thanks.
It sounds like you are running a web site, and not a web application project. A website doesn't have a project file, and therefore doesn't create a single dll. Instead it created a bunch of smaller dlls. You don't have any control over which classes, etc are in which .dll.
When you deploy your web site, you will need to delete all of these dlls and move all of the new ones over. If you don't do this, you could potentially have 2 dlls that contain the same code, and you will run into issues with code being defined twice when you JIT.
If you can, I recommend you migrate your web site to a Web Application Project, so you only have one .dll you need to worry about. There are several tutorials out there including this one for VS2005.

ASP.NET isn't automatically rebuilding

If you create an ASP.NET Web Site project and run it, you get a blank page. If you go into the default CodeBehind file, add into the Page_Load method throw new Exception();, save the file, and refresh it in the browser (without rebuilding), the server automatically rebuilds the project and the page will error.
I have a project that I am working on now where refreshing the page does not cause the project to be rebuilt (the new aspx files are used but the old DLLs are used with them). What causes this, and how do I correct it?
Is this new project a web application project by any chance? I believe you have to actually build that before changes will be seen.
Web Application Project is a separate type of project that requires all code behind to be build. The resulting dll is build under the bin folder. The code behind files are not used in execution, and is the preffered way of doing it if you don't want to expose your code at the installed web server, and to be sure execution is faster (never compiling in runtime).
When you creatied it as "ASP.NET Web Site", it is NOT a "Web Application Project".
Only code which is in App_Code will be automatically recompiled when it changes. If your code lives anywhere else, then it's part of the pre-built DLL you get when you hit "compile".
You are using the Website model. The pages will be compiled when you access them. Class Library projects in the same solution will not. Hence why you see this behaviour.
By default, the ASPX, code behind and App_Code source files get compiled. If you have a seperate project in the solution (a BLL or DAL perhaps), these will not be updated by simply refreshing the browser.
So to correct it you could do a proper build in Visual Studio, or you could move the class files you want to change into App_Code. Personally I'd stick with the former (actually I don't ever use the Website option- always Web application project).
OK. Have you got 'Edit and Continue' enabled?
MSDN

ASP.NET Web Deployment Projects: getting rid of .compiled files

I'm using a Web Deployment Project in Visual Studio 2008 in order to prepare my ASP.NET application (ASP.NET web application, not ASP.NET web site) for being copied to several servers. I have to copy the files on local staging servers, on different servers via FTP and sometimes I have to fetch them from customers' servers.
So, it would be nice to have all files for deployment in a compact form without the necessity of doing a lot of comparing between source and destination. Web deployment projects have this nice feature: compile all your aspx and ascx files into a single (additional) assembly.
I somehow found out how to get rid of aspx placeholder files on the server, now I'd like to know if there is a (maybe self-made) way to get rid of these .compiled files.
From Rick Strahl's blog:
The .Compiled file is a marker file
for each page and control in the Web
site and identifies the class used
inside of the assembly. These files
are not optional as they map the ASPX
pages to the appropriate precompiled
classes in the precompiled assemblies.
If you remove the .Compiled file, the
page that it maps will not be able to
execute and you get a nasty execution
error.
Anybody out there with a creative idea, maybe using a module/handler which intercepts the check against the .compiled files in the bin folder?
The .compile file comes from pre-compiling on deployment. So you basically have 3 options:
Keep the .compiled file
Don't pre-compile and deploy source code
Turn this in to a Web Application instead of a Web Site and compile as an assembly
I have run in to the same problem myself. I actually choose #1 in most cases when dealing with deployment of Web Sites, but on the rare occasion when I know I am going to have to maintain the site for an extended period of time, I take the time to upgrade it to a Web Application.
I don't like the .compiled files either, but nobody gets hurt if they're there. So why bother?
You might want to take a look at Virtual Path Providers (KB how to here) in ASP.NET.
Credit for this suggestion must go to Cheeso and his self answered question here:
Can I get “WAR file” type deployment with ASP.NET?
I don't know about the .compiled files, but you could set up your servers to update their files with subversion instead of manually copying the files when you compile.
So you would compile the files using the Web deployment project (not into a single assembly), put them in a repository you created for this purpose, and on each server, just do an svn update to fetch and compare the files automatically.
I know it's not what you asked for directly, but it may be a path to explore.
Add "Exclude Filter" to your deployment project:
In the Deployment Project.
Right Click on Content Files.
Click on "Exclude Filter".
Add "*.Compiled"
click OK.
and thats it.
I remember at the days when I cant do Web Application with VWD Express, I use nant script to compile the project into a single dll and deploy, that would work (so I dont need the full VS to do dll deployment too), so if you really don't want to mess your project to Web Application, maybe this is a path to check too.
You can get rid of the .compiled files by using the aspnet_merge tool with the -r option.
Removes the .compiled files for the main code assembly (code in the App_Code folder). Do not use this option if your application contains an explicit type reference to the main code assembly.
If you publish your code as updateable (in publish settings) these files are generated. Uncheck that value and republish. This is an old question I know, but no answers are clearly defined for this here.

Filter ASP.NET web application's files when deploying

I want to deploy my web application (asp.net mvc), and I need to remove all the codebehind files from my project.
Any scripts that you guys know of to do this?
I prefer using a script since I can tweak it if need be.
Just select the publish web site option on your project and it should take care of that (if you use vs).
Menu Build/Publish Website
In Visual Sudio, right click your project and select Publish... in the appearing dialog, select "Only files needed, to run this application".
The Publishing wizard will compile all codebehind files to your assembly and remove them for publishing.
I'd recommend using a web deployment project. This will compile your website and copy all of the files needed to for deployment into a new folder (without code-behind files, as they don't need to be deployed). You also get a little more control this way, as you can set up pre-build and post-build events.
For instance, I've set up a post-build event on the web deployment project to execute a batch file which copies some files into the Debug/Release folder and then zips it up, ready for FTP'ing to the production server.
First, codebehind files are not recommended for ASP.NET MVC. Codebehind is the controller for ASP.NET standard files - but in ASP.NET MVC you have far more powerful controllers.
Second, why do you need to remove codebehind files? IIS / MVC / Web.config should be taking care of ensuring that *.cs etc. files do not get served and result in a 404.

Resources