Problems using MsBuild using command line for Publish Click Once
Asked Answered
H

3

22

I have Windows application in csproj in my solution, and I want generate Publish using command line (bat, cmd).

My script is (I put \r\n for better reading):

 SET MSBUILD="%SystemRoot%\Microsoft.NET\Framework\v3.5\MSBuild.exe"
    SET CARWIN="..\..\Security.CarWin.csproj"

    rem msbuild para publish

    %MSBUILD% /target:rebuild;publish %CARWIN% 
/p:ApplicationVersion="1.0.0.0" 
/p:Configuration=release 
/p:PublishUrl="C:\ClickOnce\CarWin.WebInstall\Publicacion\" 
/p:InstallUrl="http://desserver/carwinclickonce/Publicacion/" 
/p:PublishDir="C:\ClickOnce\CarWin.WebInstall\Publicacion\" 

note: I'll try too using /target:publish

But in path PublishDir or PublishUrl (C:\ClickOnce\CarWin.WebInstall\Publicacion) not generates any files.

I have seen many posts in this site and google but I not found any solution.

Halla answered 25/1, 2010 at 8:18 Comment(1)
Possible duplicate of MSBuild doesn't respect PublishUrl property for my ClickOnce appPrisage
I
14

Take a look at this Stack Overflow question. Basically the PublishUrl property is ignored when running ClickOnce from the command line. But you can easily add the behaviour with an additional MSBuild-task.

I've created an additional MSBuild-File, for example a build.csproj. This contains a publish-task. This task first invokes the regular MS-Build of the target-project. Afterwards it copies the result to the publish-directory. Now I invoke the 'build.csproj' instead of the reguar project-file from the command-line:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="3.5" DefaultTargets="Publish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <!-- project name-->
        <ProjectName>MyExampleProject</ProjectName> 
        <!--properties for the project-build-->
        <DefaultBuildProperties>Configuration=Release</DefaultBuildProperties> 
        <!-- location of the click-once stuff, relative to the project -->
        <ProjectPublishLocation>.\bin\Release\app.publish</ProjectPublishLocation> 
        <!-- Location you want to copy the click-once-deployment. Here an windows-share-->
        <ProjectClickOnceFolder>\\TargetServer\deployments</ProjectClickOnceFolder> 
      </PropertyGroup>
      <Target Name="Publish" DependsOnTargets="Clean">
        <Message Text="Publish-Build started for build no $(ApplicationRevision)" />
        <!-- run the original build of the project -->
        <MSBuild Projects="./$(ProjectName).csproj"
        Properties="$(DefaultBuildProperties)"
        Targets="Publish"/>
        <!-- define the files required for click-once-->
        <ItemGroup>
          <SetupFiles Include="$(ProjectPublishLocation)\*.*"/>
          <UpdateFiles Include="$(ProjectPublishLocation)\Application Files\**\*.*"/>
        </ItemGroup>
        <!-- and copy them -->
        <Copy
        SourceFiles="@(SetupFiles)"
        DestinationFolder="$(ProjectClickOnceFolder)\"/>
        <Copy
        SourceFiles="@(UpdateFiles)"
        DestinationFolder="$(ProjectClickOnceFolder)\Application Files\%(RecursiveDir)"/>
      </Target>
      <Target Name="Clean">
        <Message Text="Clean project" />
        <MSBuild Projects="./$(ProjectName).csproj"
        Properties="$(DefaultBuildProperties)"
        Targets="Clean"/>
      </Target>
    </Project>
Injection answered 25/1, 2010 at 16:59 Comment(1)
Great, I was wondering if it's feasible to just use the publish location of the target project instead of having to specify it here... ?Joellyn
E
26

Use PublishDir instead of PublishUrl when running from command line.

msbuild /target:publish /p:Configuration=Release;PublishDir=c:\playground\

You can also change version, like ApplicationRevision=666;MinimumRequiredVersion=1.1

Eureetloir answered 5/12, 2013 at 16:39 Comment(2)
for PublishDir, it's important to have the ending "\"Fusain
How to specify minimumRequiredVerison in msbuild command? I tried with above recommendation, but it doesn't worked.Artamas
I
14

Take a look at this Stack Overflow question. Basically the PublishUrl property is ignored when running ClickOnce from the command line. But you can easily add the behaviour with an additional MSBuild-task.

I've created an additional MSBuild-File, for example a build.csproj. This contains a publish-task. This task first invokes the regular MS-Build of the target-project. Afterwards it copies the result to the publish-directory. Now I invoke the 'build.csproj' instead of the reguar project-file from the command-line:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="3.5" DefaultTargets="Publish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <!-- project name-->
        <ProjectName>MyExampleProject</ProjectName> 
        <!--properties for the project-build-->
        <DefaultBuildProperties>Configuration=Release</DefaultBuildProperties> 
        <!-- location of the click-once stuff, relative to the project -->
        <ProjectPublishLocation>.\bin\Release\app.publish</ProjectPublishLocation> 
        <!-- Location you want to copy the click-once-deployment. Here an windows-share-->
        <ProjectClickOnceFolder>\\TargetServer\deployments</ProjectClickOnceFolder> 
      </PropertyGroup>
      <Target Name="Publish" DependsOnTargets="Clean">
        <Message Text="Publish-Build started for build no $(ApplicationRevision)" />
        <!-- run the original build of the project -->
        <MSBuild Projects="./$(ProjectName).csproj"
        Properties="$(DefaultBuildProperties)"
        Targets="Publish"/>
        <!-- define the files required for click-once-->
        <ItemGroup>
          <SetupFiles Include="$(ProjectPublishLocation)\*.*"/>
          <UpdateFiles Include="$(ProjectPublishLocation)\Application Files\**\*.*"/>
        </ItemGroup>
        <!-- and copy them -->
        <Copy
        SourceFiles="@(SetupFiles)"
        DestinationFolder="$(ProjectClickOnceFolder)\"/>
        <Copy
        SourceFiles="@(UpdateFiles)"
        DestinationFolder="$(ProjectClickOnceFolder)\Application Files\%(RecursiveDir)"/>
      </Target>
      <Target Name="Clean">
        <Message Text="Clean project" />
        <MSBuild Projects="./$(ProjectName).csproj"
        Properties="$(DefaultBuildProperties)"
        Targets="Clean"/>
      </Target>
    </Project>
Injection answered 25/1, 2010 at 16:59 Comment(1)
Great, I was wondering if it's feasible to just use the publish location of the target project instead of having to specify it here... ?Joellyn
M
2

I don't know if this is a problem, but I noticed that you pass the /target parameter twice?

you could you use a semi-colon delimited example:

/target:rebuild;publish

MSDN Documentation on command line parameters and MSBuild

If that also does not work you could perhaps try to debug it by passing

/verbosity:diag
Meill answered 25/1, 2010 at 8:49 Comment(3)
I try /target:rebuild;publish and only /target:publish but not generates files publishing. Any idea , please ?? Thanks !!!Halla
Run it with /verbosity:diag and post that outputMeill
the logfile of output has size more than 1 MB !!! impossible post here... the issue .. I dont get publish it in the folder that I put in cmd file... thanks.Halla

© 2022 - 2024 — McMap. All rights reserved.