Publish a Web Application from the Command Line - visual-studio-2010

I've got a series of .NET 4 based web applications (WCF and Web) within the same solution, but need to selectively publish, from the command line.
I've tried various things so far, MSBuild, aspnet_compiler, but nothing, to date has worked.
I need to be able to specify the Project, not the solution, have any transforms run and have the output redirected to a folder...basically mimick the right mouse click 'Publish' option, using the File System.
In addition to all of this, I'd like to leave the projects alone - not adding msbuild files all over the place, as this is a specific build, and not necessarily related to the project.
Stuff I've tried:
Publish ASP.NET MVC 2 application from command line and Web.config transformations
Equivalent msbuild command for Publish from VS2008

Save the following script as publishProject.bat
rem publish passed project
rem params: %configuration% %destDir% %srcDir% %proj%
#echo off
SET DestPath=d:\projects\Publish\%2
SET SrcPath=d:\projects\Src\%3\
SET ProjectName=%4
SET Configuration=%1
RD /S /Q "%DestPath%" rem clear existed directory
:: build project
MSBuild "%SrcPath%%ProjectName%.vbproj" /p:Configuration=%Configuration%
:: deploy project
::/t:TransformWebConfig
MSBuild "%SrcPath%%ProjectName%.vbproj" /target:_CopyWebApplication /property:OutDir=%DestPath%\ /property:WebProjectOutputDir=%DestPath% /p:Configuration=%Configuration%
xcopy "%SrcPath%bin\*.*" "%DestPath%\bin\" /k /y
echo =========================================
echo %SrcPath%%3.vbproj is published
echo =========================================
I call it from another batch file
#echo off
rem VS2010. For VS2008 change %VS100COMNTOOLS% to %VS90COMNTOOLS%
call "%VS100COMNTOOLS%\vsvars32.bat"
SET ex=.\publishProject.bat Release
call %ex% KillerWebApp1 KillerWebApp1\KillerWebApp1 KillerWebApp1
call %ex% KillerWebApp2 KillerWebApp2\KillerWebApp2 KillerWebApp2
call %ex% KillerWebApp3 KillerWebApp3\KillerWebApp3 KillerWebApp3
call %ex% KillerWebApp4 KillerWebApp4\KillerWebApp4 KillerWebApp4
EDIT:
Code above works for most cases but not for all. I.e. we use another asp .net application and link it as virtual folder in IIS. For this situation VS2008 worked fine with code above but VS2010 also copy files from virtual directory while deploying. The following code works properly also in VS2010 (solution was found here)
Add to your project file (*.csproj, *.vbproj)
<Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
<Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." />
<MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" />
<ItemGroup>
<PublishFiles Include="$(_PackageTempDir)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(PublishFiles)" DestinationFiles="#(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" />
</Target>
Change publishProject.bat to:
rem publish passed project
rem params: %configuration% %destDir% %srcDir% %proj%
#echo off
SET DestPath=d:\projects\Publish\%2
SET SrcPath=d:\projects\Src\%3\
SET ProjectName=%4
SET Configuration=%1
:: clear existed directory
RD /S /Q "%DestPath%"
:: build and publish project
MSBuild "%SrcPath%%ProjectName%.vbproj" "/p:Configuration=%Configuration%;AutoParameterizationWebConfigConnectionStrings=False;PublishDestination=%DestPath%" /t:PublishToFileSystem

I know this is an old question, but I just learned something, so I decided I'd share: While it is 100% true that the "_CopyWebApplication" target exists and works, as of .NET 4.0 it has been superseded by the "_WPPCopyWebApplication" target in Microsoft.Web.Publishing.targets, which supports new features like web.config transformation syntax, etc.

Have you checked out WebDeploy?
This should do all the steps you need to have - it can bundle up a web app into a deployable file (a ZIP, basically), and there's an "engine" on the server that can interpret that deployable package and do all the heavy lifting for you.
Also see Scott Hanselman's Web Deployment Made Awesome: If You're Using XCopy, You're Doing It Wrong blog post - very enlightening!

My solution for CCNET with the Web.config transformation:
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>E:\VersionesCC\Trunk_4\SBatz\Gertakariak_Orokorrak\GertakariakMS\Web</workingDirectory>
<projectFile>GertakariakMSWeb2.vbproj</projectFile>
<targets>Build</targets>
<timeout>600</timeout>
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
<buildArgs>
/noconsolelogger /p:Configuration=Release /v:diag
/p:DeployOnBuild=true
/p:AutoParameterizationWebConfigConnectionStrings=false
/p:DeployTarget=Package
/p:_PackageTempDir=E:\Aplicaciones\GertakariakMS2\Web
</buildArgs>
</msbuild>
</tasks>

Related

For asp.net boilerplate core version, robocopy required for publish

When doing a "dotnet publish" on windows for a freshly downloaded asp.net boilerplate template, everything works fine, and the resulting puplish folder can be used.
However when doing the same on linux, I get the following:
/bin/sh: 2: /tmp/tmpda90e7b4d99846c4936a6816fb7d9654.exec.cmd: robocopy: not found
Is there a specific way I am supposed to do a publish for asp.net boilerplate on linux?
AspNet Boilerplate merged solution has a PrepublishScript that executing a Robocopy step. Since Linux OS has no Robocopy command, you need to remove the below line in your MyProject.Web.Host.csproj
<Exec Command="robocopy $(MSBuildProjectDirectory)\wwwroot\dist\ $(MSBuildProjectDirectory)\wwwroot\ /S /E /MOVE" IgnoreExitCode="True" />
Click here to go to the related source code line.
And you need to make that step manually; copy the content of the $(MSBuildProjectDirectory)\wwwroot\dist\ to $(MSBuildProjectDirectory)\wwwroot\
PS: MSBuildProjectDirectory is the property that will give you the full path to the project file which was invoked on the command line

Web.config transformation: Unrecognized attribute 'xmlns:xdt'. Note that attribute names are case-sensitive

I'm getting this strange intermitent bug in a MVC 3.0 project
When I build the project sometimes I get the following error message:
Unrecognized attribute 'xmlns:xdt'. Note that attribute names are
case-sensitive.
This is referring to the standard web.config tranformation file (Web.Release.config copied below)
There are no other errors or warnings. This is happening in debug mode and release.
Sometimes it clears if I clean the solution
BEGIN UPDATE
Found the issue. In the MVC Project file (MyProject.csproj) I had set build views to true
<MvcBuildViews>true</MvcBuildViews>
Once put back to false the above error goes away. I'd like to have the view build as it stops alot of stupid view code errors etc and is a performance enhancement (pages are precompiled instead of jit)
Anyone know what this is causing the error? is this a bug?
END UPDATE
<?xml version="1.0"?>
<!-- For more information on using Web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your Web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
I ran into the very same problem.
You will find lots of banter out there related to MvcBuildViews and various error conditions.
But none seem to mention this particular error.
A quick fix that worked for me was to delete the contents of the "obj" directory for the affected web project, then rebuild.
This is kind of a workaround, but you may add the following line to your pre-build commands:
del $(ProjectDir)obj\* /F /S /Q
Right click your project > Properties > Build Events > Pre-build
This works with Continuous Integration and WebDeploy:
This problem occurs the moment I set
<MvcBuildViews>true</MvcBuildViews>
in my Project file, which I need to do.
After reading and testing everything I found about this problem I have a wokraround, that also works with WebDeploy via MSBuild
MSBUild.exe ... /p:DeployOnBuild=true
You (only) need to delete the TransformWebConfig subfolder in your buildfolder during the pre- AND post-build events. It even works with continuous integration servers which break if no folder exists
Pre-build event command line:
if exist "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\" del "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\*" /F /S /Q
Post-build event command line:
if exist "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\" del "$(ProjectDir)obj\$(ConfigurationName)\transformwebconfig\*" /F /S /Q
This even works fine with Resharper which will sometimes get confused, if you delete the whole obj folder.
Make sure to set the Run the post-build event to always!!
UPDATE:
Replaced debug and release with $(ConfigurationName) and removed resulting duplicate line
I resolve my conflict by doing the same thing that Job said. Removing the attribute
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
From the main Web.config and leave it into the Web.debug.config and Web.release.config
There is another workaround from Microsoft Team. See details here.
Just copy-paste this snippet into your .csproj or .vbproj file:
<PropertyGroup>
<_EnableCleanOnBuildForMvcViews Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='' ">true</_EnableCleanOnBuildForMvcViews>
</PropertyGroup>
<Target Name="CleanupForBuildMvcViews" Condition=" '$(_EnableCleanOnBuildForMvcViews)'=='true' and '$(MVCBuildViews)'=='true' " BeforeTargets="MvcBuildViews">
<ItemGroup>
<_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\Package\**\*" />
<_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TransformWebConfig\**\*" />
<_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\CSAutoParameterize\**\*" />
<_TempWebConfigToDelete Include="$(BaseIntermediateOutputPath)**\TempPE\**\*" />
</ItemGroup>
<Delete Files="#(_TempWebConfigToDelete)" />
</Target>
This will automate the process of cleaning 'obj' folder using Build Targets.
just remove the xmlns:xdt attribute from the web.config, but keep it in web.release.config and web.debug.config.
Your transform will still work - and so will your website.
I've found this works better for me:
del "$(ProjectDir)obj\*" /F /Q
del "$(ProjectDir)obj\$(ConfigurationName)\AspnetCompileMerge\*" /F /S /Q
del "$(ProjectDir)obj\$(ConfigurationName)\CSAutoParameterize\*" /F /S /Q
del "$(ProjectDir)obj\$(ConfigurationName)\Package\*" /F /S /Q
del "$(ProjectDir)obj\$(ConfigurationName)\ProfileTransformWebConfig\*" /F /S /Q
del "$(ProjectDir)obj\$(ConfigurationName)\TempPE\*" /F /S /Q
del "$(ProjectDir)obj\$(ConfigurationName)\TransformWebConfig\*" /F /S /Q
otherwise build(s) complain about edmxResourcesToEmbed disappearing.
I have seen this too. Specifically, it had been reproducible when changing between build configurations in Visual Studio.
My workaround previously had been to delete everything in the \obj folder, but after going through my web.config closely, I found it had some erroneous text sitting outside an element (i.e. it was invalid XML).
Seemingly the config transforms was just swallowing up an exception when trying to perform the transformation.
Fixed up my web.config to be valid, and all is working as expected now.
Hope this helps someone
I've also run into this issue. For me it was caused by my having created a new debug configuration called, "DevDebug". I fixed it by making a copy the web.debug.config, named web.DevDebug.config and added it to the project.
Then, when I attempted to run the aspnet compiler, it was satisfied that it could find the right configuration version of the config file to merge in.
I just change below on web.config
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
to
<configuration>
It fixed the problem
Right click on the project, click Publish
Goto Settings -> File Publish Options
Uncheck Precompile during publishing
This will prevent the web.debug.config/web.release.config injecting the file back to the web.config if you are using visual studio publish.

VS2010 Web Publish command line version of File System deploy

Folks,
In a nutshell, I want to replicate this dialog:
It's a Visual Studio 2010 ASP.Net MVC project. If I execute this command, I get all the files I want, including the transformed web.configs in the "C:\ToDeploy" directory.
I want to replicate this on the command line so I can use it for a QA environment build.
I've seen various articles on how to do this on the command line for Remote Deploys, but I just want to do it for File System deploys.
I know I could replicate this functionality using nAnt tasks or rake scripts, but I want to do it using this mechanism so I'm not repeating myself.
I've investigated this some more, and I've found these links, but none of them solve it cleanly:
VS 2008 version, but no Web.Config transforms
Creates package, but doesn't deploy it..do I need to use MSDeploy on this package?
Deploys package after creating it above...does the UI really do this 2 step tango?
Thanks in advance!
Ok, finally figured this out.
The command line you need is:
msbuild path/to/your/webdirectory/YourWeb.csproj /p:Configuration=Debug;DeployOnBuild=True;PackageAsSingleFile=False
You can change where the project outputs to by adding a property of outdir=c:\wherever\ in the /p: section.
This will create the output at:
path/to/your/webdirectory/obj/Debug/Package/PackageTmp/
You can then copy those files from the above directory using whatever method you'd like.
I've got this all working as a ruby rake task using Albacore. I am trying to get it all done so I can actually put it as a contribution to the project. But if anyone wants the code before that, let me know.
Another wrinkle I found was that it was putting in Tokenized Parameters into the Web.config. If you don't need that feature, make sure you add:
/p:AutoParameterizationWebConfigConnectionStrings=false
I thought I'd post a another solution that I found, I've updated this solution to include a log file.
This is similar to Publish a Web Application from the Command Line, but just cleaned up and added log file. also check out original source http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild
Create an MSBuild_publish_site.bat (name it whatever) in the root of your web application project
set msBuildDir=%WINDIR%\Microsoft.NET\Framework\v4.0.30319
set destPath=C:\Publish\MyWebBasedApp\
:: clear existing publish folder
RD /S /Q "%destPath%"
call %msBuildDir%\msbuild.exe MyWebBasedApp.csproj "/p:Configuration=Debug;PublishDestination=%destPath%;AutoParameterizationWebConfigConnectionStrings=False" /t:PublishToFileSystem /l:FileLogger,Microsoft.Build.Engine;logfile=Manual_MSBuild_Publish_LOG.log
set msBuildDir=
set destPath=
Update your Web Application project file MyWebBasedApp.csproj by adding the following xml under the <Import Project= tag
<Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
<Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." />
<MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" />
<ItemGroup>
<PublishFiles Include="$(_PackageTempDir)\**\*.*" />
</ItemGroup>
<Copy SourceFiles="#(PublishFiles)" DestinationFiles="#(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" />
</Target>
this works better for me than other solutions.
Check out the following for more info:
1) http://www.digitallycreated.net/Blog/59/locally-publishing-a-vs2010-asp.net-web-application-using-msbuild
2) Publish a Web Application from the Command Line
3) Build Visual Studio project through the command line
My solution for CCNET with the Web.config transformation:
<tasks>
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
<workingDirectory>E:\VersionesCC\Trunk_4\SBatz\Gertakariak_Orokorrak\GertakariakMS\Web</workingDirectory>
<projectFile>GertakariakMSWeb2.vbproj</projectFile>
<targets>Build</targets>
<timeout>600</timeout>
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
<buildArgs>
/noconsolelogger /p:Configuration=Release /v:diag
/p:DeployOnBuild=true
/p:AutoParameterizationWebConfigConnectionStrings=false
/p:DeployTarget=Package
/p:_PackageTempDir=E:\Aplicaciones\GertakariakMS2\Web
</buildArgs>
</msbuild>
</tasks>
On VS2012 and above, you can refer to existing publish profiles on your project with msbuild 12.0, this would be equivalent to right-click and publish... selecting a publish profile ("MyProfile" on this example):
msbuild C:\myproject\myproject.csproj "/P:DeployOnBuild=True;PublishProfile=MyProfile"
I've got a solution for Visual Studio 2012: https://stackoverflow.com/a/15387814/2164198
However, it works with no Visual Studio installed at all! (see UPDATE).
I didn't checked yet whether one can get all needed stuff from Visual Studio Express 2012 for Web installation.
A complete msbuild file with inspiration from CubanX
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Publish">
<RemoveDir Directories="..\build\Release\Web\"
ContinueOnError="true" />
<MSBuild Projects="TheWebSite.csproj"
Targets="ResolveReferences;_CopyWebApplication"
Properties="Configuration=Release;WebProjectOutputDir=..\build\Release\Web;OutDir=..\build\Release\Web\bin\"
/>
</Target>
<Target
Name="Build"
DependsOnTargets="Publish;">
</Target>
</Project>
This places the published website in the Web..\build\Release folder

How to make Visual Studio copy a DLL file to the output directory?

I have a Visual Studio C++ project that relies on an external DLL file. How can I make Visual Studio copy this DLL file automatically into the output directory (debug/release) when I build the project?
Use a post-build action in your project, and add the commands to copy the offending DLL. The post-build action are written as a batch script.
The output directory can be referenced as $(OutDir). The project directory is available as $(ProjDir). Try to use relative pathes where applicable, so that you can copy or move your project folder without breaking the post-build action.
$(OutDir) turned out to be a relative path in VS2013, so I had to combine it with $(ProjectDir) to achieve the desired effect:
xcopy /y /d "$(ProjectDir)External\*.dll" "$(ProjectDir)$(OutDir)"
BTW, you can easily debug the scripts by adding 'echo ' at the beginning and observe the expanded text in the build output window.
The details in the comments section above did not work for me (VS 2013) when trying to copy the output dll from one C++ project to the release and debug folder of another C# project within the same solution.
I had to add the following post build-action (right click on the project that has a .dll output) then properties -> configuration properties -> build events -> post-build event -> command line
now I added these two lines to copy the output dll into the two folders:
xcopy /y $(TargetPath) $(SolutionDir)aeiscontroller\bin\Release
xcopy /y $(TargetPath) $(SolutionDir)aeiscontroller\bin\Debug
To do it with the GUI, first add the file(s) to the project: right-click the project, select "Add...", then "Existing Item", then browse to the file or files you want to add and click "Add". Next, tell Visual Studio to copy the file when you build: right-click the file you want to copy, select "Properties". You'll see a list of properties, including "Item Type". Change the "Item Type" to "Copy File". Hit OK and you're done.
Here's the file properties dialog:
Looking in the *.vcxproj file, the steps above add something like this:
<ItemGroup>
<CopyFileToFolders Include="libs\a.dll" />
<CopyFileToFolders Include="libs\a.dll" />
</ItemGroup>
I couldn't find any official documentation for <CopyFileToFolders>, but clearly it's supported or the GUI wouldn't use it. But, if you're doing it by hand and an undocumented item type makes you uncomfortable you can always use the well known but slightly more verbose <Content> type:
<ItemGroup>
<Content Include="libs\a.dll" >
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="libs\b.dll" >
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Add builtin COPY in project.csproj file:
<Project>
...
<Target Name="AfterBuild">
<Copy SourceFiles="$(ProjectDir)..\..\Lib\*.dll" DestinationFolder="$(OutDir)Debug\bin" SkipUnchangedFiles="false" />
<Copy SourceFiles="$(ProjectDir)..\..\Lib\*.dll" DestinationFolder="$(OutDir)Release\bin" SkipUnchangedFiles="false" />
</Target>
</Project>
(This answer only applies to C# not C++, sorry I misread the original question)
I've got through DLL hell like this before. My final solution was to store the unmanaged DLLs in the managed DLL as binary resources, and extract them to a temporary folder when the program launches and delete them when it gets disposed.
This should be part of the .NET or pinvoke infrastructure, since it is so useful.... It makes your managed DLL easy to manage, both using Xcopy or as a Project reference in a bigger Visual Studio solution. Once you do this, you don't have to worry about post-build events.
UPDATE:
I posted code here in another answer https://stackoverflow.com/a/11038376/364818
xcopy /y /d "$(ProjectDir)External\*.dll" "$(TargetDir)"
You can also refer to a relative path, the next example will find the DLL in a folder located one level above the project folder. If you have multiple projects that use the DLL in a single solution, this places the source of the DLL in a common area reachable when you set any of them as the Startup Project.
xcopy /y /d "$(ProjectDir)..\External\*.dll" "$(TargetDir)"
The /y option copies without confirmation.
The /d option checks to see if a file exists in the target and if it does only copies if the source has a newer timestamp than the target.
I found that in at least newer versions of Visual Studio, such as VS2109, $(ProjDir) is undefined and had to use $(ProjectDir) instead.
Leaving out a target folder in xcopy should default to the output directory. That is important to understand reason $(OutDir) alone is not helpful.
$(OutDir), at least in recent versions of Visual Studio, is defined as a relative path to the output folder, such as bin/x86/Debug. Using it alone as the target will create a new set of folders starting from the project output folder. Ex: … bin/x86/Debug/bin/x86/Debug.
Combining it with the project folder should get you to the proper place. Ex: $(ProjectDir)$(OutDir).
However $(TargetDir) will provide the output directory in one step.
Microsoft's list of MSBuild macros for current and previous versions of Visual Studio
I had a similar question. In my project, there were couple of external DLLs. So I created a new folder in the project called "lib" and copied all the external dlls to this folder.
Add a reference to these DLLs.
Go to Project References>dll properties and change the following properties
enter image description here

How to copy a build to test server?

Hope someone can assist me with this. Have TeamCity up and running and doing builds on various projects. I'd like to be able to copy/deploy a successful TeamCity ran build to a test server automatically.
I was thinking of using PowerShell to do this but, am open to other ideas. Can some provide me with info on how I can accomplish this.
Thanks.
I use WGet. Here are the instructions for forming the team city URL. You can do a WGet in powershell, but if you only wanted powershell for this functionality, you can just use a plain wget utility for windows.
EDIT: Here is an example from our QA deployment (names changed to protect the guilty):
"C:\Program Files (x86)\NcFTP\wget.exe" "http://teamcityserver.domain.com:8111/guestAuth/repository/download/bt6/.lastFinished/Artificat.ear"
The location of the wget isn't relevant, that is just where it happens to be. The guestAuth part of the parameter specifies the authentication type (in our case we enabled guest authorization to not have to bother with passwords - it is an internal server only anyway and protected by firewalls). The options are in the documentation I linked to.
The other interesting feature of the parameters is the bt6. That is the unique key of the build, and is different for every project. You can discover what it is by navigating the team city website to the configuration of that build - it will be there. There are also instructions for referencing the configuration by name, but we found that was too verbose to bother with.
I've been implementing this for our applications today. Using msbuild. I have found this very useful as we can add in custom steps such as modifying config files, archiving live builds and notifying people of changes.
Here is a build script you may find useful. It precompiles the application and then copies it into the deploy directory.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Deploy">
<PropertyGroup>
<WebsitePublishDirectory>Artifacts\Website</WebsitePublishDirectory>
<WebsiteDeployDirectory>\\SERVERNAME\Path\to\web\root</WebsiteDeployDirectory>
<WebsiteProject>[Project name here]</WebsiteProject>
</PropertyGroup>
<Target Name="Deploy">
<RemoveDir Directories="$(WebsitePublishDirectory)" />
<AspNetCompiler
VirtualPath="test"
PhysicalPath="$(WebsiteProject)"
TargetPath="$(WebsitePublishDirectory)"
Force="true"
Debug="false" />
<ItemGroup>
<PublishedFiles Include="$(WebsitePublishDirectory)\**" />
</ItemGroup>
<Copy SourceFiles="#(PublishedFiles)" DestinationFolder="$(WebsiteDeployDirectory)\%(RecursiveDir)" />
</Target>
</Project>
You could also install a TeamCity agent on the test server. That's actually how TeamCity was intented to be used.
I created a Post Build Script in Visual Studio like this:
c:\TeamCityBuild\pt_build.bat
exit 0
Then on the TC-server I have a .bat that looks like this:
net use r: \192.168.16.85\WebSite password /USER:domain.com\administrator
xcopy "C:\TeamCityBuild\path\WebSite*" "r:\" /R /Y /E
r: \192.168.16.85\WebSite /DELETE
if errorlevel 1 goto buildFAILED
:buildOK
echo Wehej!!!
exit 0
:buildFAILED
echo Oh NOOO!!!
exit 1
'R:' is a mapped drive to the test server.
The error handling is only needed to avoid script errors when someone builds the project on a environment without the correct folder structure.
So far everyting is working great!

Resources