Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild doesn't respect PublishUrl property for my ClickOnce app

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

(wrapped for easier reading)

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.

like image 645
TheBlueSky Avatar asked Dec 17 '09 05:12

TheBlueSky


3 Answers

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 :-)

like image 189
wallismark Avatar answered Oct 21 '22 12:10

wallismark


Some features are done by Visual-Studio and not by the MSBuild-script. So the click-once-deployment behaves differently 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">
    <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>
like image 20
Gamlor Avatar answered Oct 21 '22 12:10

Gamlor


I'll put in my 2 cents, this syntax seems to work (right or wrong):

/p:publishUrl="C:\\_\\Projects\\Samples\\artifacts\\Web\\"
like image 2
Reece Bradley Avatar answered Oct 21 '22 12:10

Reece Bradley