【问题标题】:How to publish a WPF clickonce app when building a solution?构建解决方案时如何发布 WPF clickonce 应用程序?
【发布时间】:2017-11-08 06:54:02
【问题描述】:

我有一个包含许多项目的解决方案,其中一些项目的输出类型为 exe。

我在 MsBuild 调用中使用以下参数

/target:publish /p:PublishDir="$(build.artifactstagingdirectory)\

但是,这会发布输出类型为 exe 的所有项目。但是,我只想发布一个特定的项目。

我读过的大部分内容都引用了名为PublishProfile。但是,我看不到为此项目类型创建PublishProfile 的方法。当我单击发布时,我会看到一个基本的发布向导,并且发布设置存储在 .csproj 文件中,而不是 .pubxml 文件中。那么如何请求发布特定项目呢?

【问题讨论】:

  • 您想构建解决方案但只使用一个 MSBuild 命令行发布特定项目吗?如何使用命令行发布特定项目:msbuild "xx.csproj" /target:publish /p:PublishDir="$(build.artifactstagingdirectory)\"

标签: .net wpf visual-studio-2015 msbuild clickonce


【解决方案1】:

但是,我看不到为此项目类型创建 PublishProfile 的方法。当我单击发布时,我会看到一个基本的发布向导,并且发布设置存储在 .csproj 文件中,而不是 .pubxml 文件中。那么如何请求发布特定项目呢?

PublishProfile 用于 web 项目,不能点击一次。正如您所说,“基本发布向导和发布设置存储在 .csproj 文件中,而不是 .pubxml 文件中”,因此 PublishProfile 不应该是正确的选择。

如果您想使用 msbuild 从解决方案中发布特定项目,简单的方法是构建整个解决方案但只发布一个项目文件,例如:

msbuild.exe "ProjectName.csproj" /target:publish /p:PublishDir="$(build.artifactstagingdirectory)\

如果使用一个命令行构建和发布是你的持久性,你可以在你想要发布的项目文件中自定义一个目标来发布项目。 For example:

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

使用此自定义目标,您无需发布项目,只需构建解决方案即可。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 2014-02-02
    • 1970-01-01
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 2019-01-02
    • 1970-01-01
    • 2022-06-28
    相关资源
    最近更新 更多