MSBuild 不尊重我的 ClickOnce 应用程序的 PublishUrl 属性 [英] MSBuild doesn't respect PublishUrl property for my ClickOnce app

查看:26
本文介绍了MSBuild 不尊重我的 ClickOnce 应用程序的 PublishUrl 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个批处理文件,以便一键发布我们拥有的几个 ClickOnce 应用程序.我为此使用了 msbuild,作为示例,下面的命令行显示了我是如何做到的:

msbuild我的应用程序.sln/t:发布/p:配置=发布/p:PublishUrl="C:Apps"/v:正常 >日志.txt

(为便于阅读包装)

当我运行上述命令时,它会在发布目录中构建并发布应用程序,即 bin elease!知道为什么 msbuild 在上面的示例中不尊重 PublishUrl 属性吗?

PS:我也尝试了不同的组合,包括删除配置",使用重建"和发布仅"作为目标,并删除引号但没有任何成功.

解决方案

某些功能由 Visual-Studio 完成,而不是由 MSBuild 脚本完成.因此,从命令行执行时,单击一次部署的行为会有所不同.

  • ApplicationRevision 不会随着每次构建而增加.这仅在从 Visual Studio 执行时有效
  • 在某些情况下,不使用 PublishUrl.引用自 MSDN:<块引用>

    例如,您可以将 PublishURL 设置为 FTP 路径,并将 InstallURL 设置为 Web URL.在这种情况下,PublishURL 仅在 IDE 中用于传输文件,而不在命令行构建中使用.最后,如果您想发布一个 ClickOnce 应用程序,该应用程序从安装它的单独位置更新自身,则可以使用 UpdateUrl.

我创建了一个特殊的 MSBuild 文件来执行此操作.它运行发布目标并将文件复制到正确的位置.

根据 alhambraeidos 的要求,构建文件的示例.它基本上运行常规的 VisualStudio 构建,然后将单击一次数据复制到真正的发布文件夹.请注意,删除了一些特定于项目的内容,因此它可能已损坏.此外,它不会增加内部版本号.这是由我们的 Continues-Build-Server 完成的:

<?xml version="1.0" encoding="utf-8"?><Project ToolsVersion="4.0" DefaultTargets="Publish" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><属性组><!-- 要构建的项目的文件夹--><ProjLocation>..YourProjectFolder</ProjLocation><ProjLocationReleaseDir>$(ProjLocation)inRelease</ProjLocationReleaseDir><ProjPublishLocation>$(ProjLocationReleaseDir)app.publish</ProjPublishLocation><!-- 这是网络文件夹,它提供了用于单击一次的人工制品.在这之后构建项目实际上是部署在服务器上--><DeploymentFolder>D:server
eleases</DeploymentFolder></属性组><目标名称="发布" DependsOnTargets="清理"><Message Text="Publish-Build started for build no $(ApplicationRevision)"/><MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Publish"/><项目组><SchoolPlannerSetupFiles Include="$(ProjPublishLocation)*.*"/><SchoolPlannerUpdateFiles Include="$(ProjPublishLocation)Application Files***.*"/></项目组><复制SourceFiles="@(SchoolPlannerSetupFiles)"DestinationFolder="$(DeploymentFolder)"/><复制SourceFiles="@(SchoolPlannerUpdateFiles)"DestinationFolder="$(DeploymentFolder)Application Files\%(RecursiveDir)"/><CallTarget Targets="RestoreLog"/></目标><目标名称="干净"><Message Text="清理项目:"/><MSBuild Projects="$(ProjLocation)/YourProject.csproj" Properties="Configuration=Release" Targets="Clean"/></目标></项目>

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

解决方案

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)inRelease</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
eleases</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>

这篇关于MSBuild 不尊重我的 ClickOnce 应用程序的 PublishUrl 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆