【问题标题】:How to emulate Visual Studios Publish in an Azure Pipeline如何在 Azure 管道中模拟 Visual Studio 发布
【发布时间】:2019-10-29 20:17:32
【问题描述】:

我试图弄清楚如何将我的 WPF 应用程序发布到多个位置。

原因:没有所有用户都可以访问的目录/网络位置。连接到 azure 管道的本地托管代理可以访问允许所有用户至少有一个位置来访问应用程序的位置(所需的发布位置)。

一段时间后,我终于能够发布到这些位置。现在我想转换我的发布操作来模拟 Visual Studio 的功能。

我的意思是我希望发布文件夹看起来像:

1. A folder called "Application Files" 
     Containing subfolders 
         MyApplicationName_1_0_0_19
         MyApplicationName_1_0_0_20
         ...
2. `MyApplicationName.application` 
3. `Setup.exe` <- Note: I delete this file since it requires admin privileges to use. I've only included it here because Visual Studios Publish feature creates it on the first publish.

而不是它当前的外观,这是我当前发布的所有应用程序文件。

原因:运行MyApplicationName.application 会在用户桌面上创建一个快捷方式,并且当应用程序启动时它会检查更新的版本。

最后一个任务是发布到所需位置的位置。

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool: Default

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: MSBuild@1
  inputs:
    solution: 'Tenant Tool Analytics Module/*.csproj'
    msbuildArchitecture: 'x64'


- task: VisualStudioTestPlatformInstaller@1
  inputs:
    packageFeedSelector: 'nugetOrg'
    versionSelector: 'latestStable'


- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    vsTestVersion: 'toolsInstaller'

- task: MSBuild@1
  inputs:
      solution: 'Tenant Tool Analytics Module/*.csproj'
      msbuildArguments: '/target:Publish /p:OutDir=c:\test2\'
      msbuildArchitecture: x64

注意:我没有使用 Azure 部署组,因为这需要管理员权限,并且获得这些权限是一个漫长而缓慢的过程(目前正在进行中且无法保证)。如果最好的解决方案是通过那里,请发表评论,当我有权为部署组运行“注册脚本 (PowerShell)”时,我会发布一个新问题。

我没有创建文件“MyApplicationName.application”,而是由 Visual Studios 发布功能创建的。我在下面添加了其中的代码。

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
  <assemblyIdentity name="MyApplicationName.application" version="1.0.0.20" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" xmlns="urn:schemas-microsoft-com:asm.v1" />
  <description asmv2:publisher="MyApplicationName" asmv2:product="MyApplicationName" xmlns="urn:schemas-microsoft-com:asm.v1" />
  <deployment install="true" co.v1:createDesktopShortcut="true">
    <subscription>
      <update>
        <beforeApplicationStartup />
      </update>
    </subscription>
    <deploymentProvider codebase="file://[Publish Path On Shared Network Drive]" />
  </deployment>
  <compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
    <framework targetVersion="4.7.2" profile="Full" supportedRuntime="4.0.30319" />
  </compatibleFrameworks>
  <dependency>
    <dependentAssembly dependencyType="install" codebase="Application Files\MyApplicationName_1_0_0_20\MyApplicationName.exe.manifest" size="7240">
      <assemblyIdentity name="MyApplicationName.exe" version="1.0.0.20" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" type="win32" />
      <hash>
        <dsig:Transforms>
          <dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
        </dsig:Transforms>
        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
        <dsig:DigestValue>6P...gi+j6...nY=</dsig:DigestValue>
      </hash>
    </dependentAssembly>
  </dependency>
</asmv1:assembly>

【问题讨论】:

  • 这是什么类型的应用程序?根据您的问题,听起来您想使用部署组将应用程序部署到最终用户机器?也很想了解为什么不是所有用户都可以访问共享资源(无论是 UNC 共享还是 URL)
  • 它是一个 WPF 应用程序。目前为了测试,我在共享网络驱动器上有一个位置,应用程序将发布到该位置。用户运行“MyApplicationName.application”一次,然后他们使用在他们的桌面上创建的快捷方式。由于我无法控制的限制,并非所有用户都可以访问单个共享网络驱动器(由于权限),这就是为什么我需要为多个位置重复当前过程。做一些研究我现在明白 Visual Studio 不能发布到多个位置。这就是我尝试使用 azure 管道的原因。

标签: c# visual-studio msbuild azure-devops azure-pipelines


【解决方案1】:

由于 WPF 框架是 .NET 的一部分,您可以在构建管道中选择 .NET DeskTop 模板并使用 Publish Artifact 任务将 .Net 桌面应用构建工件部署到共享网络驱动器文件夹。

Artifact publish location设置为A file share,然后你需要输入你的网络驱动器文件夹路径。

如果要部署到多个网络驱动器,可以添加多个Publish Artifact 任务。有类似问题的可以参考这个case

如果你想部署到大量位置并且不想添加多个任务,更好的方法是使用部署组。

【讨论】:

  • 这将是正确的起点。对我来说,我必须在我的论点中包含更多内容。最终对我有用的解决方案发布在下面。
【解决方案2】:

看来我需要将属性 OutputPath 和 OutDir 添加到我的 msbuildArguments 以使我的部署正常工作。

- task: MSBuild@1
  inputs:
      solution: 'Tenant Tool Analytics Module/*.csproj'
      msbuildArguments: '/target:Publish 
      /p:ApplicationVersion=$(AssemblyVersion) 
      /p:UpdateEnabled=true /p:UpdateMode=Foreground 
      /p:ProductName=TenantAnalyticsTool 
      /p:InstallUrl=c:\sandbox\deploytesting\siteA
      /p:PublishUrl=c:\sandbox\deploytesting\siteA
      /p:UpdateUrl=c:\sandbox\deploytesting\siteA
      /p:OutputPath=c:\sandbox\deploytesting\siteA
      /p:OutDir=c:\sandbox\deploytesting\siteA '
      msbuildArchitecture: x64

【讨论】:

    猜你喜欢
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-14
    • 1970-01-01
    相关资源
    最近更新 更多