Showing posts with label Visual Studio 2010. Show all posts
Showing posts with label Visual Studio 2010. Show all posts

Thursday, April 14, 2011

Publishing VS2010 Web Projects using command line

Since I started developing using Visual Studio 2010, I was impressed about WebDeploy integration into IDE. Particularly I was found one key publishing feature very useful for me:

image

Especially I use “File System” publish method. I was searching a way to execute this publish scenario from command prompt, maybe on machine without Visual Studio installed.

It took me a couple of hours of googling, but finally I found 2 blog posts that made me to complete the puzzle: Daniel Chambers post and Sayed Ibrahim Hashimi post.

Here is my working combination:

  1. Add {ProjectName}.wpp.targets file to Web app project folder (right aside of .csproj file), where {ProjectName} is the name of project (name of project file).
  2. Add new target to the file from #1. This target is responsible to copy site files to the specified destination:
       1: <?xml version="1.0" encoding="utf-8"?>
       2: <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
       3:    <Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
       4:     <Error Condition="'$(PublishDestination)'==''" Text="The PublishDestination property must be set to the intended publishing destination." />
       5:     <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" />
       6:     
       7:     <ItemGroup>
       8:         <PublishFiles Include="$(_PackageTempDir)\**\*.*" />
       9:     </ItemGroup>
      10:  
      11:     <Copy SourceFiles="@(PublishFiles)" DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" />
      12: </Target>
      13: </Project>
  3. Call new target defining actual parameters:
  4.    1: %windir%\Microsoft.NET\Framework\v4.0.30319\MSBuild Mvc.csproj /T:PublishToFileSystem /p:Configuration=Release;PublishDestination=C:\Sites\Mvc;AutoParameterizationWebConfigConnectionStrings=false

Please note last parameter ‘AutoParameterizationWebConfigConnectionStrings’. This parameter set to false in order to keep web.config file transformed according to build configuration BUT NOT tokenized.