Making a build that removes source CS files - asp.net

How to make a build in VS 2010 within an ASP.NET MVC application that would remove all of the source code (CS and VB) files? When I build a website or web app I usually copy the contents of the entire solution to the hosting server. Mostly clients get the source but sometimes I do not want to expose the source to the hosting server thus only the Public (or Content) folder, views, masters and the built DLL should be copied.
Manual solutions are not applicable. What do you guys use?

Click Publish from the Build menu, then select File System and deploy into a folder. The contents of that folder should have all the stuff you want and nothing more.

You can add del commands to the post-build script. (Perhaps wrapped up in a batch file)
You can even write a C# program that deletes the files, then run that in the post-build script.

Related

Run equivalent to "Build Page" command for Visual Studio web site project from command line

As outlined in Tip/Trick: Optimizing ASP.NET 2.0 Web Project Build Performance with VS 2005, the "Build Page" command available within Visual Studio web site projects does the following:
the solution will compile all of the class library projects like before, then compile the /app_code directory and Global.asax file, and then instead of re-verifying all pages within the web-site it will only verify the current page you are working on, and any user controls that the page references.
Is there a way to access this functionality from msbuild and / or the command line?
I am setting up an automated build of a large Visual Studio web site project (based on Kentico CMS), which consists of:
a large number of CMS-related pages and user controls that we do not change
a small number of custom "web part" user controls that we are actively developing, all within a CMSWebParts/Custom directory within the web site
Pre-compiling the entire site using aspnet_compiler takes up to 10 minutes, which is too slow for a commit build. Ideally, I'd like to introduce a step that pre-compiles just our custom code. Note that we don't actually deploy the pre-compiled output (not recommended for Kentico sites), this step is intended only to validate the code in the .ascx files.
The best way I've found to reduce the pre-compile time for small changes to large web sites is to use the ASP.Net Compilation Tool (aspnet_compiler.exe) with in-place compilation.
Our build script runs the tool using the following command:
aspnet_compiler.exe -v / -p C:\path\to\MyWebSite
This command specifies the physical path to the web site but does not set the targetDir option, which results in the application being compiled in-place.
The benefit of in-place compilation is that aspnet_compiler will by default only compile files that have changed since the web site was last compiled (you can force it to recompile everything with the -c option). For example, when I run the above command against the web site for the first time, it takes about 10 mins to run. If I then change a single file and run it again, it only takes 30 seconds or so.
You may be curious as to how the compilation tool "knows" which files have changed. Compiling in-place doesn't modify the application being compiled, i.e., you won't end up with files like App_Web_xdqqvn5q.dll and default.aspx.cdcab7d2.compiled in the bin folder of your web application. The output is actually generated within the "Temporary ASP.NET Files" folder. When you specify a physical path (rather than an IIS metabase), a folder within your profile is used, e.g. C:\Users\your.name\AppData\Local\Temp\Temporary ASP.NET Files. Your web application source code is cross-referenced with data stored in Temporary ASP.NET Files to work out what has changed.
I think this might be of help for what you need to accomplish:
http://msdn.microsoft.com/en-us/library/dd293881.aspx
From what I read you can run the build from Visual Studio Command Prompt or from the windows command prompt.
Update:
I couldn't find anything on the internet relating to building only one page but using aspnet_compiler without -c parameter should speed up the compiling process since it will only recompile what has changed. If only thing that has changed since last build was the content of one .aspx page then running the compiler should act similar to Build Page.
-c
Specifies that the application to be compiled should be fully rebuilt.
Components that have already been compiled are compiled again. If this
option is omitted, the tool builds only those parts of the application
that have been modified since compilation was last performed.
aspnet_compiler usage is explained on this page:
http://msdn.microsoft.com/en-us/library/ms229863.aspx

asp.net single file publish

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.

Making a website/project Portable - Check List

Good evening/morning/after/noon.
I have an ASP.net 3.5 website and I am using vb.net in VWD 2008 Express, I am also using MS SQL Server 2008 Express, I used ajax tabs and a textBox characters counter control developed by https://web.archive.org/web/20211020202742/https://www.4guysfromrolla.com/ The database is attached with MS SQL Server Management Studio Express and the files are stored in the SQL default "Data" folder.
The whole project's code and forms are stored in a folder in my E drive. I need to hand the whole project to another coworker who have to finish it, please describe in steps how can i make my website portable (like i can put it all in a folder that he can carry around in his flash disk).
One more thing, I already finished my side of the project, I need to ship it out to this other programmer.
Can anyone suggest something like a: Checklist or Must Do list to achieve this?
PS: I have had a problem trying to move the project from one server to the other, the project seems to look for the dlls of the AJAX control and the textBox counter where i originally unzipped the folders in which they cam in, which i think was on my desktop, although when i added those controls to the Tools tab, i created a new tab, then i choose the dll from the where i unzipped the controls source code, aint that enough?
Thanks in advance
I use the following folder structure for all my solutions
solution
docs
libs
scripts
sql
src
docs - contains all documentation
libs - contains all non GAC'ed framework dlls that the solution uses. You should copy the dlls in here first then reference them this way they are a relivive reference from the src folder.
scripts - build scripts for designers who don't have VS installed and the build server
sql - all sql scripts for creating your database
src - all source for the solution we break this folder up into the following file/folder structure
solution.sln
project1
project2
website1
website2
etc
Now when you copy the solution folder everything is relative so will work.
I'd advise that you add your project to source control, I'd recommend Subversion/SVN and the TortoiseSVN client

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.

Web Deployment Project builds files that are no longer part of the project

This is the error I get:
Error 101 Could not load type
'control'. /Test.vbproj/x.ascx 1 1
WebDeployProject
This is a left over file that was part of the project last week, but one of the developers deleted it from the project. I have to manually delete the file in order to get the WDP to build. Is there a way to tell the WDP to ignore the files that are not part of the project or to see that these files are not part of the project and delete them?
You'll need to use your source control tools to find and remove local files that aren't under source control.
For instance, if you're using TFS, do the following:
Open Source Control Explorer (View -> Other Windows -> Source Control Explorer)
Right-click on the path in TFS that corresponds to your local working copy and select Compare
Use your TFS path as Source Path and your local working copy as Target Path
Under View Options, select "Show items that exist only in target path"
You've now got a list of all the files that exist in your local working copy but aren't in source control. For each file, either delete your local copy or add it to source control.
It could have something do to with the type of web project is it.
If it's a web site, then the compiler will attempt to compile every file in the folder. However, if it's a Web Application Project, then it will only compile those that you've specifically added as part of the project.
If you have recently deleted/removed a file from your project then you need go to Project > "Show all files" and all removed files will apear in your solution explorer. You can delete the file, /x.ascx and rebuild your WDP.
It has nothing to do with the type of Web project: http://amiraryani.wordpress.com/2008/11/06/web-deployment-project-aspparse-could-not-load-type/.
A Web Site itself considers files under its root directory as part of the site.
A Web Application Project itself allows you to customize build actions, etc. on a per-file basis.
A Web Deployment Project, however, will try to include files under the root directory (a la a Web Site), even if the WDP is associated with a WAP. That's why it doesn't matter which kind of Web project it is.
EDIT: To clarify, it would matter what type of Web project you are using if you were trying to Build, Debug, or Publish that project itself instead of using a WDP.

Resources