chrisl08
chrisl08

Reputation: 1658

MSBuild ClickOnce app: FTP Upload files after build

I am using MS build to publish my ClickOnce app, in Visual Studio 2017 developer command line to a remote ftp site. How do I initiate the FTP file upload that starts in Visual Studio after build? This is my command line, which builds the project:

msbuild  /target:publish -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\IIC\IIC.UI.vbproj"

Upvotes: 0

Views: 1292

Answers (2)

chrisl08
chrisl08

Reputation: 1658

There are 2 problems with command line Click Once deployment: (1) Auto Incrementing option from the publish property page of a project is not honored from the command line, and (2) the subject of the question, starting the FTP upload to the remote site.

Solution (with Visual Studio 2017 Developer Command Prompt v15.7.3)

  1. Download community ms build tasks from here: https://github.com/loresoft/msbuildtasks
  2. Unload the project and open with notepad++ or your editor of choice and import the community ms build tasks. Follow the instructions on their github page.
  3. Add file ProjectName.version.txt with just one line with the version information of your project. For example:

1.2.78.1341

The numbers correspond to {Major}.{Minor}.{Build}.{ApplicationRevision}

  1. Add the following target to the bottom of the project, which uses the Version and FileUpdate community tasks:

       <Target Name="beforePublishCmd">
    
      <Message Text="revision before: 3.0.0.$(ApplicationRevision)"/>
       <Version VersionFile="ProjectName.version.txt" BuildType="Automatic" Major="3" Minor="0" Build="0" RevisionType="Increment">
          <Output TaskParameter="Major" PropertyName="Major" />
          <Output TaskParameter="Minor" PropertyName="Minor" />
          <Output TaskParameter="Build" PropertyName="Build" />
          <Output TaskParameter="Revision" PropertyName="ApplicationRevision" />
          </Version>
          <Message Text="revision after: 3.0.0.$(ApplicationRevision)"/>
          <FileUpdate Files="ProjectName.vbproj"
                Regex="&lt;ApplicationRevision&gt;(\d+)"
                ReplacementText="&lt;ApplicationRevision&gt;$(ApplicationRevision)" />
    </Target>
    

  2. Call the above target from the command line BEFORE calling the publish target, like so:

    msbuild /target:beforePublishCmd -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\ProjectName.vbproj"

  3. Add an "afterPublish" target, which uses the FtpUploadDirectoryContent community task. This target is automatically called after the publish target finishes.

     <Target Name="afterPublish">
    
    <PropertyGroup>
      <CurrentDate>$([System.DateTime]::Now.ToString(yyyy MMM dd HH:mm:ss))</CurrentDate>
    </PropertyGroup>
    
     <FtpUploadDirectoryContent 
             ServerHost="projectname.org"
             Username="*****"
             Password="*****"
             LocalDirectory=".\bin\Release\app.publish"
             RemoteDirectory="/"
             Recursive="true"
         />
    <Exec Command="C:\Progra~1\TortoiseSVN\bin\svn commit ..\ --non-interactive --message &quot;Release 3.0.0.$(Revision) on $(CurrentDate): $(commitMessage)&quot;"/>          
     </Target>
    

    1. Finally, call the publish target from the command line:

      msbuild /target:publish -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\ProjectName.vbproj"

Upvotes: 1

Leo Liu
Leo Liu

Reputation: 76850

MSBuild ClickOnce app: Upload files after build

You can add a copy task into your project file to upload files after build:

To accomplish this, unload your project. Then at the very end of the </project>, just before the end-tag, place below scripts:

<ItemGroup>
    <UploadFiles Include="ThePathOfYourUploadFiles\*.*"/>
</ItemGroup>

<Target Name="AfterBuild">
    <Copy
        SourceFiles="@(UploadFiles)"
        DestinationFolder="PathWhereYouWantTouploadYourUploadFiles"
    />
</Target>

With this target, Visual Studio/MSBuild will upload the files after build.

Hope this helps.

Upvotes: 0

Related Questions