none
Publishing a ClickOnce project with command-line MSBuild

    Question

  • You can build the Publish target of a .csproj with the command-line MSBuild.exe, but when the Visual Studio IDE publishes a project it also copies it to a designated location and in Beta 2 appears to do something clever with preserving old .application manifests.

    Is there a way to have MSBuild.exe perform these extra steps from the command line? Perhaps I'm building the wrong target?
    Thursday, April 28, 2005 3:44 PM

Answers

  • Graeme,

    MSBuild won't actually perfom the publish (i.e. the physical transfer of files etc) when building from the command-line - as you've discovered. The simple reason is that the functionality to do that is in the IDE itself.

    MSBuild will only perform the build related tasks.

    Sorry!

    ..Kieran
    Friday, April 29, 2005 9:06 PM
    Moderator

All replies

  • Graeme,

    MSBuild won't actually perfom the publish (i.e. the physical transfer of files etc) when building from the command-line - as you've discovered. The simple reason is that the functionality to do that is in the IDE itself.

    MSBuild will only perform the build related tasks.

    Sorry!

    ..Kieran
    Friday, April 29, 2005 9:06 PM
    Moderator
  • When you run "msbuild /t:publish" is it possible to have it create the publish.htm page and also iterate the version # of the folder?
    • Proposed as answer by IMx Thursday, December 24, 2009 5:47 PM
    Tuesday, January 10, 2006 4:43 PM
  • FYI, This was the solution to my problem...

    <Project DefaultTargets="DoPublish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        <PropertyGroup>
     <MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\lib\msbuild</MSBuildCommunityTasksPath>
        </PropertyGroup>
        <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets"/>
        <PropertyGroup Condition="!Exists('$(Configuration)')">
            <Configuration>Debug</Configuration>
        </PropertyGroup>
        <PropertyGroup Condition="!Exists('$(CCNetLabel)')">
            <CCNetLabel>0</CCNetLabel>
        </PropertyGroup>
        <PropertyGroup>
     <ClickOnceBuildDirectory>AlgoCollateral\bin\$(Configuration)\AlgoCollateral.publish</ClickOnceBuildDirectory>
            <Version>1.0.0.$(CCNetLabel)</Version>
    <ClickOnceInstallDirectory>\\mtlv5webdev\Deployment\AlgoCollateral</ClickOnceInstallDirectory>
        </PropertyGroup>
        <ItemGroup>
            <ClickOnceFiles Include="$(ClickOnceBuildDirectory)\**\*.*"/>
            <IndigoServiceFiles Include="Algo.Collateral.Services\**\*.*"/>
        </ItemGroup>
        <Target Name="DoPublish">
            <MSBuild Projects="AlgoCollateral.v5.sln" Targets="Clean;Build" Properties="ApplicationVersion=$(Version)"/>
            <MSBuild Projects="AlgoCollateral/AlgoCollateral.csproj" Targets="Publish" Properties="ApplicationVersion=$(Version)" />
            <!-- Write publish.htm file for ClickOnce -->
            <Copy SourceFiles=".\Build\publish.htm" DestinationFiles="$(ClickOnceInstallDirectory)\publish.htm"/>
            <Copy SourceFiles="AlgoCollateral\bin\$(Configuration)\AlgoCollateral.application" DestinationFiles="$(ClickOnceInstallDirectory)\AlgoCollateral.application"/>
            <FileUpdate Files="$(ClickOnceInstallDirectory)\publish.htm"
                        IgnoreCase="true"
                        Multiline="true"
                        Singleline="false"
                        Regex="{VERSION}"
                        ReplacementText="$(Version)"
                        Force="true"/>                      
            <!-- Move Click Once Files -->
            <MakeDir Directories="$(ClickOnceInstallDirectory)"/>
            <Copy SourceFiles="@(ClickOnceFiles)"
     DestinationFiles="@(ClickOnceFiles->'$(ClickOnceInstallDirectory)\%(RecursiveDir)%(Filename)%(Extension)')"/>     
        </Target>
    </Project>
    • Proposed as answer by IMx Thursday, December 24, 2009 5:47 PM
    Friday, January 13, 2006 7:58 PM
  • Can you tell me how you're keeping track/incrementing the ApplicationVersion number?  It appears you are simply passing it in through the CCNetLabel property.  That's my biggest challenge right now with trying to build ClickOnce from the command-line.
    Friday, March 03, 2006 2:33 PM
  • the CCNetLabel comes from the "CruiseControl.net" label the it increments on its own.
    Wednesday, March 08, 2006 10:37 PM
  • Upon further investigation into the Microsoft.Common.targets file in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727, I found the PublishDir property used... Once I added it to the msbuild command line arguments (/p:PublishDir=c:\Inetpub\wwwroot\publish), then msbuild properly built the  ClickOnce deployment there... Next up, I need to figure out how to get the folder to auto increment--as done by Visual Studio. All this done to hopefully configure CruiseControl.Net to auto-deploy my ClickOnce project.

    --
    Brady P. Merkel
    Go Gators! --;==;<
    Thursday, March 09, 2006 3:12 PM
  • Has anyone had any luck with msbuild command line generating the publish.htm file? I am able to get it to publish to the directory of my choice (/p:PublishDir) but it does not produce two files... AppName_1_0_0_0.application and publish.htm. Am I missing something?
    • Proposed as answer by Tom Newman WTG Wednesday, May 18, 2011 6:35 PM
    Sunday, August 13, 2006 6:49 AM
  • I'm having trouble with too.  Running msbuild from the command line to publish, everything seems identical to running publish from the IDE except the publish.htm file is missing.  Does anyone have any ideas?
    Tuesday, August 29, 2006 11:32 AM
  • When looking at the publish.htm, that file contains no info about what version of all those present is the current one. However, it contains some java script dealing with reg exp which appears to figure those things out for itself. Thus, there should be no reason to actually regenerate that file. The fact that the IDE does regenerate it every time may very well mean nothing at all. In fact I tried exchanging the newly generated file for the file from the last version with no ill effects at all.

    I'm also having trouble with the version number thingy. You can supply the version number as a parameter (not bad at all if you execute your msbuild from some other application, like NAnt). However, it doesn't really seem to care what version you supply, so I guess I've got it all wrong.
    Tuesday, October 24, 2006 2:11 PM
  • Sorry.
    I was wrong. Stupidity is a desease hard to cure, so please don't hit me. It'll only make it worse...
    Tuesday, October 24, 2006 2:15 PM
  • This answer is actually wrong...it will publish to the directory of your choice but it doesn't create the Publish.htm. The settings within a .csproj file are msbuild targets, tasks, and properties. The property for where to publish can be passed in.

    This works fine:

    <MSBuild Projects="@(ProjectsToBuild)"

    Targets="Publish"

    Properties="Configuration=$(Configuration);

    Platform=$(Platform);

    PublishDir=$(BuildDropLocation)\;

    ApplicationVersion=$(ApplicationVersion);

    PublisherName=$(Company);      

    PublishUrl=http://localhost/SmartClient/;

    InstallUrl=http://localhost/SmartClient/">

    <Output ItemName="OutputFiles" TaskParameter="TargetOutputs"/>

    </MSBuild>

     

    Since the property can be passed in via an MSBuild script then it can be passed in via commandline too.

     

    -Ken Villines

     

    Wednesday, November 29, 2006 4:05 PM
  • I'm confused after having read through the above.

    So, can I (or can I not) use MSBuild to publish my Win app to a specified URL?

    For our app, we must publish it to 10 different servers (10 different contained cattle feed yards).  So I would love to have my version ready to be deployed, build it, and then go to the command prompt and be able to type something like:

    msbuild /target:publish /property:PublishUrl=http://123.45.67.89/MyApp
    msbuild /target:publish /property:PublishUrl=http://123.45.67.90/MyApp
    msbuild /target:publish /property:PublishUrl=http://123.45.67.91/MyApp

    etc

    because then I could write a script to automate the publish to multiple locations instead of having to do it 10x in the VS IDE every time)

    But from everything I'm reading, MSBuild will not publish to a URL, but only to a local folder.  And it does not handle publish.htm and other needed files.

    So should I abandon MSBuild or will it be able to do what I need?

    Thanks!
    Ron

    Sunday, December 17, 2006 1:59 PM
  • Couldn't you use msbuild to publish to a local dir on the web server (publishDir), and later put a virtual directory matching publishUrl on top of it so it becomes accessible via your publishUrl?
    Thursday, March 29, 2007 1:51 PM
  • I am able to build the project. But when I specify the Install URL and Publish URL, the user doesn't have access to the path.

    So I need to impersonate with some other credential. But I couldn't find any way to provide alternate username and password.

    Please let me know, how can I do it.

    Once I do this I need to integrate the same to CruseControl.Net for Continuous Integration.
    Wednesday, July 23, 2008 6:15 AM
  • At least the PublishUrl property is actually PublishDir
    Wednesday, September 03, 2008 8:54 AM
  • Hi.
    Anyone notice differences in the publish directory, building a sln from the IDE vs cruise control? I'm getting some dll's in different locations (with CC is in the root and with the IDE is in bin).

    Thx
    Thursday, November 06, 2008 5:47 PM
  • ok so forgive me for asking a begginers question here...

    I want to publish a click-once application using MSBuild and command scripts.  I see a lot of great blogs here for generating the publish.htm and version number.  If I have to edit or add MSBuild targets, tasks and properties to the auto-generated *.csproj (of start-up application), where and how do I do it?  Or do I create a new file with .csproj extension which calls the other dependent projects to build?  Sorry not much of a build expert....
    Tuesday, February 03, 2009 4:32 PM
  • try this for creating the publish.htm file. Version # is a different problem...
    http://wallism.wordpress.com/2009/12/08/clickonce-creating-publish-page-from-msbuild/
    Tuesday, December 08, 2009 12:56 AM
  • try this for creating the publish.htm file. Version # is a different problem...
    http://wallism.wordpress.com/2009/12/08/clickonce-creating-publish-page-from-msbuild/

    Thanks for releasing the info, It's comprehensive.
    Saturday, January 22, 2011 8:22 AM
  • BTW, I found that I had to run the msbuild command using /target:clean,rebuild,publish. Otherwise, the properties I was overriding (ProductName, PublishUrl, ect) weren't used because a prior .application file was being published.

    Friday, February 18, 2011 4:27 PM
  • Another MSDN page seems to dissagree with this:

    http://msdn.microsoft.com/en-us/library/ms165431.aspx

    • Proposed as answer by Alden Snow Thursday, July 21, 2011 1:47 PM
    Thursday, July 21, 2011 1:47 PM
  • If someone working for me told me that they had embedded implementation code in the user interface, then I would be having serious words with them about how to code, and I'm only 27 with 3 years experience. How do Microsoft let this kind of thing happen?
    Tuesday, July 10, 2012 2:47 PM