1

ClickOnce publish with IDE works normal.

When trying to publish via MSBuild command line

%MSBUILD% /target:publish /p:Configuration=Release;PublishDir="REMOTE_FOLDER"

only Project.exe and Setup.exe copies.

When try to %MSBUILD% /target:publish command then all necessary files copies to the build\app.publish folder

How do I publish via command line same ClickOnce settings which IDE uses

PS this question similar but not the same

Emin Hasanov
  • 1,299
  • 1
  • 13
  • 29

1 Answers1

3

How do I publish via command line same ClickOnce settings which IDE uses

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

If you want to publish via command line same ClickOnce settings which IDE uses, you can use a custom target to achieve it. Edit your project(csproj) file (right click project node -> unload project -> edit xxx.csproj) and add the following code in it:

  <PropertyGroup>
    <ProjLocation>D:\Test\Projects\ClickOncePublish\ClickOncePublish</ProjLocation>
    <ProjLocationReleaseDir>$(ProjLocation)\bin\Debug</ProjLocationReleaseDir>
    <ProjPublishLocation>$(ProjLocationReleaseDir)\app.publish</ProjPublishLocation>
    <DeploymentFolder>D:\Test\Publish\</DeploymentFolder>
  </PropertyGroup>


  <Target Name="Test" DependsOnTargets="Clean">

    <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
        Properties="$(DefaultBuildProperties)"
        Targets="Publish"/>

    <ItemGroup>
      <SetupFiles Include="$(ProjPublishLocation)\*.*"/>
      <UpdateFiles Include="$(ProjPublishLocation)\Application Files\**\*.*"/>
    </ItemGroup>


    <Copy SourceFiles="@(SetupFiles)" DestinationFolder="$(DeploymentFolder)\" />
    <Copy SourceFiles="@(UpdateFiles)" DestinationFolder="$(DeploymentFolder)\Application Files\%(RecursiveDir)"/>
  </Target>

  <Target Name="Clean">
    <Message Text="Clean project" />
    <MSBuild Projects="$(ProjLocation)\$(ProjectName).csproj"
    Properties="$(DefaultBuildProperties)"
    Targets="Clean"/>
  </Target>

Then you can build the project with the MSBuild command line:

msbuild /target:test

After execute the build command, all the expected files are publish via command line same ClickOnce settings which IDE uses. enter image description here

Note: You should change the value of ProjLocation to the path of your project.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Thanks!!! great job. but must delete ` ` lines because of circular – Emin Hasanov Aug 09 '17 at 08:22
  • But what to do for copying publish.htm file also – Emin Hasanov Aug 09 '17 at 10:19
  • @EminHasanov, I do not have publish.htm file in the default project. But you can try to specify a command line parameters as follows:/property:WebPage=publish.htm. Once you are passing these parameters to MSBUILD it will move your publish.htm up to your publish location.http://codemonkeyking.blogspot.sg/2009/04/nantmsbuild-clickonce-publishing.html. If this not help you. you can open new thread with some detailed info, I will try my best to give you a solution. – Leo Liu Aug 10 '17 at 01:29