views:

533

answers:

2

Hi everyone,

I'm trying to make a batch file to publish the few ClickOnce application we have in one click. I'm using msbuild for that, and as an example the below command line shows how I'm doing it:

msbuild MyApp.sln /t:Publish /p:Configuration=Release /p:PublishUrl="C:\Apps\" /v:normal > Log.txt

when I run the above command it builds and publish the application in the release directory, i.e. bin\release! Any idea why msbuild doesn't respect PublishUrl property in my example above?

PS: I tried also different combinations including remove 'Configuration', use 'Rebuild' and 'PublishOnly' as targets, and remove the the quotation marks but without any success.

Thanks in advance,

Essam

+1  A: 

Some features are done by Visual-Studio and not by the MSBuild-script. So the click-once-deployment behaves diffrently when it's executed from the command-line.

  • The ApplicationRevision isn't increased with every build. This works only when is exectued from Visual Studio
  • In in somecases, the PublishUrl isn't used. Quote from MSDN: "For example, you could set the PublishURL to an FTP path and set the InstallURL to a Web URL. In this case, the PublishURL is only used in the IDE to transfer the files, but not used in the command-line builds. Finally, you can use UpdateUrl if you want to publish a ClickOnce application that updates itself from a separate location from which it is installed."

I've created a special MSBuild-file which does this things. It runs the publish-target and copies then the files to the right location.

An example of the build-file, as requested by alhambraeidos. It basically runs the regular VisualStudio-build and then copies the click-once data to the real release folder. Note that removed some project-specific stuff, so it's maybe broken. Furthermore it doesn't increase the build-number. Thats done by our Continues-Build-Server:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Publish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    <PropertyGroup>
        <!-- the folder of the project to build -->
        <ProjLocation>..\YourProjectFolder</ProjLocation>
        <ProjLocationReleaseDir>$(ProjLocation)\bin\Release</ProjLocationReleaseDir>
        <ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
        <!-- This is the web-folder, which provides the artefacts for click-once. After this
         build the project is actually deployed on the server -->
        <DeploymentFolder>D:\server\releases\</DeploymentFolder>
    </PropertyGroup>


    <Target Name="Publish" DependsOnTargets="Clean">
        <Message Text="Publish-Build started for build no $(ApplicationRevision)" />
        <MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Publish"/>   


        <ItemGroup>
            <SchoolPlannerSetupFiles Include="$(ProjPublishLocation)\*.*"/>
            <SchoolPlannerUpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
        </ItemGroup>
        <Copy
            SourceFiles="@(SchoolPlannerSetupFiles)"
            DestinationFolder="$(DeploymentFolder)\"
        />
        <Copy
            SourceFiles="@(SchoolPlannerUpdateFiles)"
            DestinationFolder="$(DeploymentFolder)\Application Files\%(RecursiveDir)"
        />      
        <CallTarget Targets="RestoreLog"/>
    </Target>
    <Target Name="Clean">   
        <Message Text="Clean project:" />
        <MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Clean"/>
    </Target>       
</Project>
Gamlor
Please, any sample of that special msbuild file..
alhambraeidos
I added a example. Its a shortened version I use. There's certainly room for improvment.
Gamlor
+1  A: 

You are setting the wrong property. Try PublishDir instead.

You can pass it into msBuild as you are or you can set it in the project file (or maybe the sln file too, not sure I always use the project file.) like this

      <PropertyGroup>
    <PublishDir>C:\Dev\Release\$(BuildEnvironment)\</PublishDir>
  </PropertyGroup>

I've just done a few blog posts on MsBuild and ClickOnce stuff, check it out you 'should' find them useful...

Good luck :-)

wallismark