<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Sayed Ibrahim Hashimi - MSBuild, Web Deploy (MSDeploy), ASP.NET - ClickOnce</title>
    <link>http://sedodream.com/</link>
    <description>MSBuild, C#, Visual Studio and more</description>
    <language>en-us</language>
    <copyright>Sayed Ibrahim Hashimi</copyright>
    <lastBuildDate>Sat, 18 Feb 2012 18:47:30 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>sayed.hashimi@gmail.com</managingEditor>
    <webMaster>sayed.hashimi@gmail.com</webMaster>
    <item>
      <trackback:ping>http://sedodream.com/Trackback.aspx?guid=d9d1333e-0ff0-4fb4-b92a-72631e92442f</trackback:ping>
      <pingback:server>http://sedodream.com/pingback.aspx</pingback:server>
      <pingback:target>http://sedodream.com/PermaLink,guid,d9d1333e-0ff0-4fb4-b92a-72631e92442f.aspx</pingback:target>
      <dc:creator>Ibrahim</dc:creator>
      <wfw:comment>http://sedodream.com/CommentView,guid,d9d1333e-0ff0-4fb4-b92a-72631e92442f.aspx</wfw:comment>
      <wfw:commentRss>http://sedodream.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d9d1333e-0ff0-4fb4-b92a-72631e92442f</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The other day I saw a question on StackOverflow (link in resources below) asking How
you can create a Web Deploy (AKA MSDeploy) package when publishing a ClickOnce project.
The easiest way to do this is to use the Web Deploy command line utility, msdeploy.exe.
With the command line you can easily create an MSDeploy package from a folder with
a command like the following:
</p>
        <pre class="brush: csharp;">    %msdeploy% 
      -verb:sync 
      -source:contentPath="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\app.publish" 
      -dest:package="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\co-pkg.zip"</pre>
        <p>
 
</p>
        <p>
Here you can see that I’m using the sync verb, along with a contentPath provider (<em>which
points to a folder</em>) as the source and the destination is using the package provider,
this point to where I want the package to be stored.
</p>
        <p>
Now that we understand how to create an MSDeploy package from a folder we need to
extend the ClickOnce publish process to create a package. I’m not a ClickOnce expert,
but the ClickOnce publish process is captured in MSBuild so after investigating for
a bit I found the following relevant details.
</p>
        <ul>
          <li>
The ClickOnce publish process is contained in the Microsoft.Common.targets file</li>
          <li>
The ClickOnce publish process is tied together through the <strong>Publish</strong> target</li>
          <li>
ClickOnce prepares the files to be published in a folder under bin named app.publish
which is governed by the MSBuild property <strong>PublishDir</strong></li>
        </ul>
        <p>
Now that we know what target to extend as well as what property we can use to refer
to the folder which has the content we can complete sample. We need to edit the project
file. Below is the full contents which I have placed at the bottom of the project
file (right above &lt;/Project&gt;).
</p>
        <pre class="brush: xml;">  &lt;PropertyGroup&gt;
    &lt;WebDeployPackageName Condition=" '$(WebDeployPackageName)'=='' "&gt;$(MSBuildProjectName).zip&lt;/WebDeployPackageName&gt;
    &lt;!--Unless specified otherwise, the tools will go to HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1 to get the installpath for msdeploy.exe.--&gt;
    &lt;MSDeployPath Condition="'$(MSDeployPath)'==''"&gt;$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\3@InstallPath)&lt;/MSDeployPath&gt;
    &lt;MSDeployPath Condition="'$(MSDeployPath)'==''"&gt;$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2@InstallPath)&lt;/MSDeployPath&gt;
    &lt;MSDeployPath Condition="'$(MSDeployPath)'==''"&gt;$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1@InstallPath)&lt;/MSDeployPath&gt;
    &lt;MSDeployExe Condition=" '$(MSDeployExe)'=='' "&gt;$(MSDeployPath)msdeploy.exe&lt;/MSDeployExe&gt;
  &lt;/PropertyGroup&gt;
  &lt;Target Name="CreateWebDeployPackage" AfterTargets="Publish" DependsOnTargets="Publish"&gt;
    &lt;!--
    %msdeploy% 
      -verb:sync 
      -source:contentPath="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\app.publish" 
      -dest:package="C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\co-pkg.zip"
      --&gt;
    &lt;PropertyGroup&gt;
      &lt;Cmd&gt;"$(MSDeployExe)" -verb:sync -source:contentPath="$(MSBuildProjectDirectory)\$(PublishDir)" -dest:package="$(OutDir)$(WebDeployPackageName)"&lt;/Cmd&gt;
    &lt;/PropertyGroup&gt;
    &lt;Message Text="Creating web deploy package with command: $(Cmd)" /&gt;
    &lt;Exec Command="$(Cmd)" /&gt;
  &lt;/Target&gt;</pre>
        <p>
Here I’ve created a couple properties as well as a new target, CreateWebDeployPackage.
I have declared the property WebDeployPackageName which will be the name (excluding
path) of the Web Deploy package which gets created. This defaults to the name of the
project, but you can override it if you want. Next I define the property, MSDeployPath,
which points to msdeploy.exe. It will pick the latest version.
</p>
        <p>
The CreateWebDeployPackage target just constructs the full command line call which
needs to be executed and invokes it using the Exec MSBuild task. There are a couple
subtle details on the target itself though which are worth pointing out. The target
has declared <strong>AfterTargets=”Publish”</strong> which means that it will be invoked
after the Publish target. It also declares <strong>DependsOnTargets=”Publish”</strong>.
Which means that whenever the target gets invoked that Publish will need to be executed
before <strong>CreateWebDeployPackage</strong>. 
</p>
        <p>
Now that we have defined these updates when you publish your ClickOnce project (wither
through Visual Studio or the command line/build servers) a Web Deploy package will
be generated in the output folder which you can use to incrementally publish your
ClickOnce app to your web server. You can find the latest version of this sample on
my <a href="https://github.com/sayedihashimi/sayed-samples/tree/master/ClickOnceCreateWebPackage">github
repository</a>.
</p>
        <p>
Sayed Ibrahim Hashimi <a href="https://twitter.com/#!/sayedihashimi">@SayedIHashimi</a></p>
        <p>
Resources
</p>
        <ul>
          <li>
StackOverflow question: <a href="http://stackoverflow.com/q/9292986/105999">Create
a clickonce webdeploy package</a></li>
          <li>
            <a href="http://technet.microsoft.com/en-us/library/dd569106(WS.10).aspx">MSDeploy.exe
verb</a>
          </li>
          <li>
            <a href="http://technet.microsoft.com/en-us/library/dd569034(WS.10).aspx">MSDeploy
contentPath provider</a>
          </li>
          <li>
            <a href="http://technet.microsoft.com/en-us/library/dd569019(WS.10).aspx">MSDeploy
package provider</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/x8zx72cd.aspx">MSBuild Exec task</a>
          </li>
        </ul>
      </body>
      <title>How to create a Web Deploy package when publishing a ClickOnce project</title>
      <guid isPermaLink="false">http://sedodream.com/PermaLink,guid,d9d1333e-0ff0-4fb4-b92a-72631e92442f.aspx</guid>
      <link>http://sedodream.com/2012/02/18/HowToCreateAWebDeployPackageWhenPublishingAClickOnceProject.aspx</link>
      <pubDate>Sat, 18 Feb 2012 18:47:30 GMT</pubDate>
      <description>&lt;p&gt;
The other day I saw a question on StackOverflow (link in resources below) asking How
you can create a Web Deploy (AKA MSDeploy) package when publishing a ClickOnce project.
The easiest way to do this is to use the Web Deploy command line utility, msdeploy.exe.
With the command line you can easily create an MSDeploy package from a folder with
a command like the following:
&lt;/p&gt;
&lt;pre class="brush: csharp;"&gt;    %msdeploy% 
      -verb:sync 
      -source:contentPath=&amp;quot;C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\app.publish&amp;quot; 
      -dest:package=&amp;quot;C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\co-pkg.zip&amp;quot;&lt;/pre&gt;
&lt;p&gt;
&amp;#160;
&lt;/p&gt;
&lt;p&gt;
Here you can see that I’m using the sync verb, along with a contentPath provider (&lt;em&gt;which
points to a folder&lt;/em&gt;) as the source and the destination is using the package provider,
this point to where I want the package to be stored.
&lt;/p&gt;
&lt;p&gt;
Now that we understand how to create an MSDeploy package from a folder we need to
extend the ClickOnce publish process to create a package. I’m not a ClickOnce expert,
but the ClickOnce publish process is captured in MSBuild so after investigating for
a bit I found the following relevant details.
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The ClickOnce publish process is contained in the Microsoft.Common.targets file&lt;/li&gt;
&lt;li&gt;
The ClickOnce publish process is tied together through the &lt;strong&gt;Publish&lt;/strong&gt; target&lt;/li&gt;
&lt;li&gt;
ClickOnce prepares the files to be published in a folder under bin named app.publish
which is governed by the MSBuild property &lt;strong&gt;PublishDir&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Now that we know what target to extend as well as what property we can use to refer
to the folder which has the content we can complete sample. We need to edit the project
file. Below is the full contents which I have placed at the bottom of the project
file (right above &amp;lt;/Project&amp;gt;).
&lt;/p&gt;
&lt;pre class="brush: xml;"&gt;  &amp;lt;PropertyGroup&amp;gt;
    &amp;lt;WebDeployPackageName Condition=&amp;quot; '$(WebDeployPackageName)'=='' &amp;quot;&amp;gt;$(MSBuildProjectName).zip&amp;lt;/WebDeployPackageName&amp;gt;
    &amp;lt;!--Unless specified otherwise, the tools will go to HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1 to get the installpath for msdeploy.exe.--&amp;gt;
    &amp;lt;MSDeployPath Condition=&amp;quot;'$(MSDeployPath)'==''&amp;quot;&amp;gt;$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\3@InstallPath)&amp;lt;/MSDeployPath&amp;gt;
    &amp;lt;MSDeployPath Condition=&amp;quot;'$(MSDeployPath)'==''&amp;quot;&amp;gt;$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\2@InstallPath)&amp;lt;/MSDeployPath&amp;gt;
    &amp;lt;MSDeployPath Condition=&amp;quot;'$(MSDeployPath)'==''&amp;quot;&amp;gt;$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IIS Extensions\MSDeploy\1@InstallPath)&amp;lt;/MSDeployPath&amp;gt;
    &amp;lt;MSDeployExe Condition=&amp;quot; '$(MSDeployExe)'=='' &amp;quot;&amp;gt;$(MSDeployPath)msdeploy.exe&amp;lt;/MSDeployExe&amp;gt;
  &amp;lt;/PropertyGroup&amp;gt;
  &amp;lt;Target Name=&amp;quot;CreateWebDeployPackage&amp;quot; AfterTargets=&amp;quot;Publish&amp;quot; DependsOnTargets=&amp;quot;Publish&amp;quot;&amp;gt;
    &amp;lt;!--
    %msdeploy% 
      -verb:sync 
      -source:contentPath=&amp;quot;C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\app.publish&amp;quot; 
      -dest:package=&amp;quot;C:\Temp\_NET\WebPackageWithClickOnce\WebPackageWithClickOnce\bin\Debug\co-pkg.zip&amp;quot;
      --&amp;gt;
    &amp;lt;PropertyGroup&amp;gt;
      &amp;lt;Cmd&amp;gt;&amp;quot;$(MSDeployExe)&amp;quot; -verb:sync -source:contentPath=&amp;quot;$(MSBuildProjectDirectory)\$(PublishDir)&amp;quot; -dest:package=&amp;quot;$(OutDir)$(WebDeployPackageName)&amp;quot;&amp;lt;/Cmd&amp;gt;
    &amp;lt;/PropertyGroup&amp;gt;
    &amp;lt;Message Text=&amp;quot;Creating web deploy package with command: $(Cmd)&amp;quot; /&amp;gt;
    &amp;lt;Exec Command=&amp;quot;$(Cmd)&amp;quot; /&amp;gt;
  &amp;lt;/Target&amp;gt;&lt;/pre&gt;
&lt;p&gt;
Here I’ve created a couple properties as well as a new target, CreateWebDeployPackage.
I have declared the property WebDeployPackageName which will be the name (excluding
path) of the Web Deploy package which gets created. This defaults to the name of the
project, but you can override it if you want. Next I define the property, MSDeployPath,
which points to msdeploy.exe. It will pick the latest version.
&lt;/p&gt;
&lt;p&gt;
The CreateWebDeployPackage target just constructs the full command line call which
needs to be executed and invokes it using the Exec MSBuild task. There are a couple
subtle details on the target itself though which are worth pointing out. The target
has declared &lt;strong&gt;AfterTargets=”Publish”&lt;/strong&gt; which means that it will be invoked
after the Publish target. It also declares &lt;strong&gt;DependsOnTargets=”Publish”&lt;/strong&gt;.
Which means that whenever the target gets invoked that Publish will need to be executed
before &lt;strong&gt;CreateWebDeployPackage&lt;/strong&gt;. 
&lt;/p&gt;
&lt;p&gt;
Now that we have defined these updates when you publish your ClickOnce project (wither
through Visual Studio or the command line/build servers) a Web Deploy package will
be generated in the output folder which you can use to incrementally publish your
ClickOnce app to your web server. You can find the latest version of this sample on
my &lt;a href="https://github.com/sayedihashimi/sayed-samples/tree/master/ClickOnceCreateWebPackage"&gt;github
repository&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Sayed Ibrahim Hashimi &lt;a href="https://twitter.com/#!/sayedihashimi"&gt;@SayedIHashimi&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Resources
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
StackOverflow question: &lt;a href="http://stackoverflow.com/q/9292986/105999"&gt;Create
a clickonce webdeploy package&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://technet.microsoft.com/en-us/library/dd569106(WS.10).aspx"&gt;MSDeploy.exe
verb&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://technet.microsoft.com/en-us/library/dd569034(WS.10).aspx"&gt;MSDeploy
contentPath provider&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://technet.microsoft.com/en-us/library/dd569019(WS.10).aspx"&gt;MSDeploy
package provider&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/x8zx72cd.aspx"&gt;MSBuild Exec task&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;</description>
      <comments>http://sedodream.com/CommentView,guid,d9d1333e-0ff0-4fb4-b92a-72631e92442f.aspx</comments>
      <category>ClickOnce</category>
      <category>IIS</category>
      <category>Microsoft</category>
      <category>MSBuild</category>
      <category>MSDeploy</category>
      <category>web</category>
    </item>
  </channel>
</rss>