MSBuild doesn't respect PublishUrl property for my ClickOnce app
Asked Answered
A

4

30

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.

Allegorical answered 17/12, 2009 at 5:19 Comment(2)
Use PublishDir instead of PublishUrl. Problem solved.Brocatel
Use PublishDir=C:\Temp with no quotes around the directory name. This worked for me.Faggoting
C
16

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>
Coldblooded answered 17/12, 2009 at 10:54 Comment(2)
I added a example. Its a shortened version I use. There's certainly room for improvment.Coldblooded
This is not related to the problem. The problem is he's confused PublishUrl with PublishDir. The two parameters are not the same and do different things.Brocatel
I
40

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...

Illimitable answered 1/2, 2010 at 0:44 Comment(4)
<MSBuild Projects="$(My.sln)" Targets="Publish" Properties="PublishDir=$(MyPublishLocation)" /> works for me with MSBuild 4Slap
@Lee Grissom: Oh, you didn't have to go this far... After all, without your comment, mine has incomplete information too. But since it can't be helped now, I'll summarize them both here: 1) $(PublishDir) can be either a local path or a UNC; 2) As of 3.5, it doesn't have to be '\'-terminated unlike other dir paths such as SolutionDir, but I'd not rely on this inconsistency.Condemn
The PublishDir property seems to need backslash-termination for me with MSBuild 4.0.30319.18213.Rachealrachel
When I add /p:PublishDir=%InstallUrl% msbuild fails with invalid switch so I am confused... how can we pass it into msbuild?Sunday
C
16

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>
Coldblooded answered 17/12, 2009 at 10:54 Comment(2)
I added a example. Its a shortened version I use. There's certainly room for improvment.Coldblooded
This is not related to the problem. The problem is he's confused PublishUrl with PublishDir. The two parameters are not the same and do different things.Brocatel
B
2

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

/p:publishUrl="C:\\_\\Projects\\Samples\\artifacts\\Web\\"
Bamboo answered 10/2, 2016 at 19:58 Comment(0)
M
0

For me, the soultion was to escape the path.

Instead of:

/p:PublishUrl="C:\Apps\"

Put:

/p:PublishUrl="C:\\Apps\\"
Mihrab answered 24/8, 2020 at 10:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.