MsBuild 在目标处发布多个文件夹并且不使用输入参数
MsBuild publishing multiple folders at target and not using input parameters
我正在将 WPS 应用程序部署到多个不同的共享网络驱动器。每个应用程序都必须针对不同的数据库。最重要的是,因为我使用的是 clickOnce 部署,所以每个位置都需要自己的 PublishUrl 和 InstallUrl。
我目前有一个可以部署到每个位置的管道(最终我会将其分解为多个管道)。
问题在于它在发布时会创建两个文件夹。一个 MyAppName
和另一个 MyAppNameapp.publish
它没有设置 InstallUrl
、PublishUrl
、UpdateUrl
或 $(AssemblyVersion)
并且(不知道是否是实际的问题)将 deploymentProvider 代码库设置为我本地代理中的一个文件夹(用于 运行 此管道)。
Folder:MyAppName
Contains
A published version of my application
Folder:MyAppNameapp.publish
Contains
Setup.exe
MyAppName.application
Inside File
<deploymentProvider codebase="[Folder inside my local agent]" />
Missing InstallUrl, PublishUrl, UpdateUrl
MyAppName.exe
Folder:Application Files
Contains
Folder:MyAppNameapp_$(AssemblyVersion)
Contains
A published version of my application
如何限制 MsBuild 仅创建 MyAppNameapp.publish
(但重命名为 MyAppName
)
这是用于创建这些文件夹的 MsBuild 任务。
- 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
我试过:
- 将 OutputPath 和 OutDir 重定向到不同的位置,但随后在 c:\sandbox\deploytesting\siteA
处没有创建任何内容。
-删除两者会导致不创建文件夹。如果我只删除一个(其中一个)MSBuild 不会复制所有文件。
完整的 yaml
# 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: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
新的 MSBuild@1 测试。
- task: MSBuild@1
inputs:
solution: 'Tenant Tool Analytics Module/*.csproj'
msbuildArguments: '/t:Publish
/p:ApplicationVersion=$(Build.BuildId)
/p:UpdateEnabled=true
/p:UpdateMode=Foreground
/p:ProductName=TenantAnalyticsTool
/p:OutputPath=c:\sandbox\deploytesting\siteC
/p:InstallUrl=c:\sandbox\deploytesting\siteC
/p:PublishUrl=c:\sandbox\deploytesting\siteC'
msbuildArchitecture: x64
结果:文件夹结构保持不变
MyAppName.application
内部
<?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="MyAppName" version="1.0.0.34" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="CBRE" asmv2:product="Tenant Tool Analytics Module" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true" co.v1:createDesktopShortcut="true">
<subscription>
<update>
<beforeApplicationStartup />
</update>
</subscription>
<deploymentProvider codebase="file://catd...[Not a location specified in the pipe].../MyAppName.application" />
</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\Tenant Tool Analytics Module_198\Tenant Tool Analytics Module.exe.manifest" size="8606">
<assemblyIdentity name="Tenant Tool Analytics Module.exe" version="1.0.0.34" 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>R5zudfS3VXtM5dKoEFbHYoZih0Sxr8CjX33H5FgvBk8=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
</asmv1:assembly>
/t:Publish
将发布到 属性 /p:OutputPath=siteA
中定义的文件夹。并且将创建一个子文件夹 publish。所以这个例子将发布到文件夹 siteA\publish
/p:OutDir
用于 /t:build
。它将包含构建结果中的文件。
对于你的情况,我认为你只能使用 /p:OutputPath
,而不是 /p:OutDir
。
至于$(AssemblyVersion)
未设置。这是因为您的管道 variables 中未定义 AssemblyVersion。管道中的语法 $()
将查找管道 variables
中定义的变量或管道预定义变量。
终于对我有用的 YAML。重复这两个 MSBuild 任务,我可以将应用程序发布到网络驱动器。
# 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'
NewBuildID: $(BuildID)
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: MSBuild@1
inputs:
solution: 'Tenant Tool Analytics Module/*.csproj'
msbuildArguments: '
/p:UpdateEnabled=true
/p:UpdateMode=Foreground
/p:ProductName="Tenant Analytics Tool"
/p:BootstrapperEnabled=false
'
msbuildArchitecture: 'x64'
- task: MSBuild@1
inputs:
solution: 'Tenant Tool Analytics Module/*.csproj'
msbuildArguments: '/t:Publish
/p:UpdateEnabled=true
/p:UpdateMode=Foreground
/p:ProductName="Tenant Analytics Tool"
/p:PublishDir=H:\sandbox\deploytesting\SiteA\
/p:UpdateUrl=\CATD...[Network Location not network drive]... \sandbox\deploytesting\siteA\
/p:BootstrapperEnabled=false
'
msbuildArchitecture: x64
我正在将 WPS 应用程序部署到多个不同的共享网络驱动器。每个应用程序都必须针对不同的数据库。最重要的是,因为我使用的是 clickOnce 部署,所以每个位置都需要自己的 PublishUrl 和 InstallUrl。
我目前有一个可以部署到每个位置的管道(最终我会将其分解为多个管道)。
问题在于它在发布时会创建两个文件夹。一个 MyAppName
和另一个 MyAppNameapp.publish
它没有设置 InstallUrl
、PublishUrl
、UpdateUrl
或 $(AssemblyVersion)
并且(不知道是否是实际的问题)将 deploymentProvider 代码库设置为我本地代理中的一个文件夹(用于 运行 此管道)。
Folder:MyAppName
Contains
A published version of my application
Folder:MyAppNameapp.publish
Contains
Setup.exe
MyAppName.application
Inside File
<deploymentProvider codebase="[Folder inside my local agent]" />
Missing InstallUrl, PublishUrl, UpdateUrl
MyAppName.exe
Folder:Application Files
Contains
Folder:MyAppNameapp_$(AssemblyVersion)
Contains
A published version of my application
如何限制 MsBuild 仅创建 MyAppNameapp.publish
(但重命名为 MyAppName
)
这是用于创建这些文件夹的 MsBuild 任务。
- 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
我试过:
- 将 OutputPath 和 OutDir 重定向到不同的位置,但随后在 c:\sandbox\deploytesting\siteA
处没有创建任何内容。
-删除两者会导致不创建文件夹。如果我只删除一个(其中一个)MSBuild 不会复制所有文件。
完整的 yaml
# 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: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
新的 MSBuild@1 测试。
- task: MSBuild@1
inputs:
solution: 'Tenant Tool Analytics Module/*.csproj'
msbuildArguments: '/t:Publish
/p:ApplicationVersion=$(Build.BuildId)
/p:UpdateEnabled=true
/p:UpdateMode=Foreground
/p:ProductName=TenantAnalyticsTool
/p:OutputPath=c:\sandbox\deploytesting\siteC
/p:InstallUrl=c:\sandbox\deploytesting\siteC
/p:PublishUrl=c:\sandbox\deploytesting\siteC'
msbuildArchitecture: x64
结果:文件夹结构保持不变
MyAppName.application
内部<?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="MyAppName" version="1.0.0.34" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="amd64" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="CBRE" asmv2:product="Tenant Tool Analytics Module" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true" co.v1:createDesktopShortcut="true">
<subscription>
<update>
<beforeApplicationStartup />
</update>
</subscription>
<deploymentProvider codebase="file://catd...[Not a location specified in the pipe].../MyAppName.application" />
</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\Tenant Tool Analytics Module_198\Tenant Tool Analytics Module.exe.manifest" size="8606">
<assemblyIdentity name="Tenant Tool Analytics Module.exe" version="1.0.0.34" 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>R5zudfS3VXtM5dKoEFbHYoZih0Sxr8CjX33H5FgvBk8=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
</asmv1:assembly>
/t:Publish
将发布到 属性 /p:OutputPath=siteA
中定义的文件夹。并且将创建一个子文件夹 publish。所以这个例子将发布到文件夹 siteA\publish
/p:OutDir
用于 /t:build
。它将包含构建结果中的文件。
对于你的情况,我认为你只能使用 /p:OutputPath
,而不是 /p:OutDir
。
至于$(AssemblyVersion)
未设置。这是因为您的管道 variables 中未定义 AssemblyVersion。管道中的语法 $()
将查找管道 variables
中定义的变量或管道预定义变量。
终于对我有用的 YAML。重复这两个 MSBuild 任务,我可以将应用程序发布到网络驱动器。
# 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'
NewBuildID: $(BuildID)
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '$(solution)'
- task: MSBuild@1
inputs:
solution: 'Tenant Tool Analytics Module/*.csproj'
msbuildArguments: '
/p:UpdateEnabled=true
/p:UpdateMode=Foreground
/p:ProductName="Tenant Analytics Tool"
/p:BootstrapperEnabled=false
'
msbuildArchitecture: 'x64'
- task: MSBuild@1
inputs:
solution: 'Tenant Tool Analytics Module/*.csproj'
msbuildArguments: '/t:Publish
/p:UpdateEnabled=true
/p:UpdateMode=Foreground
/p:ProductName="Tenant Analytics Tool"
/p:PublishDir=H:\sandbox\deploytesting\SiteA\
/p:UpdateUrl=\CATD...[Network Location not network drive]... \sandbox\deploytesting\siteA\
/p:BootstrapperEnabled=false
'
msbuildArchitecture: x64