
Visual Studio 2005 has features that can used to publish a website in a production server or a staging server.When you compile files using the Publish Web Site utility the source code is removed. The marked up code in the .aspx files can also be removed optionally. After compilation the .aspx pages point to the compiled versions. With this feature the source code of your pages are safe. Accessing your code by others is difficult. This is one of the features that are more useful for those who want their code to be safe.
Question is how to automate it?
1. Add target to .csproj fileEnsure your web application project contains :
2. Call hidden task _CopyWebApplicationCall task from msbuild:
3. Resolve references to other projectsUnfortunatelly task _CopyWebApplicaiton does not copy output from referenced project so you have to do it manually by calling
ResolveReferences task
Update: Publishing Websites with cascade dependency (2009.02.03)It's quite common that you have project structure like on image below. Web site on top of Business Logic Layer, which is on top of Data Access Layer.
Unfortunately, solution posted above does not solve second degree references (references of references) and therefore. When project is built with code above only first degree are propery copied to output directory.

In order to configure all degree references to be copied you have to specify both
- WebProjectOutputDir - where website will be published
- OutDir - where all assemblies should be placed (bin folder>
In MsBuild script you can use snippet as below:
<MSBuild Projects="WebApplication\WebApplication.csproj"
Properties="Configuration=Release;WebProjectOutputDir=..\build\Release\Web\;OutDir= ..\builda\Release\Web\bin\"
Targets="ResolveReferences;_CopyWebApplication" />
Thanks to Maciej Grzyb for solution
http://maciek79.secondbrain.com