如何在YAML管道中指定.NET Framework版本?

时间:2020-10-21 12:01:35

标签: yaml azure-pipelines azure-pipelines-yaml

我对YAML极为陌生-我正在尝试使用版本B中发布的工件DLL更新插件库(请参见下面的YAML),但是我仍然收到以下错误:

enter image description here

如何在YAML中指定.NET Framework,以便它不尝试使用旧版本?我需要使用4.6.2。我浏览了每个Microsoft Doc,发现可以在运行测试中指定它,但是运气不好,试图找到如何为构建设置它。

请澄清一下,下面的YAML成功运行了,我可以下载DLL,但是在更新插件注册后,将导致错误。

'''

trigger: none

pool:
  vmImage: 'windows-latest'

steps:

- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: 'A/A.sln'

#Build the solutions
- task: VSBuild@1
  displayName: 'Build A Library'
  inputs:
    solution: 'A/A.sln'
    msbuildArgs: '/p:DeployOnBuild=true 
                  /p:WebPublishMethod=Package 
                  /p:PackageAsSingleFile=true 
                  /p:SkipInvalidConfigurations=true 
                  /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" 
                  /p:DeployIisAppPath="Default Web Site"'
    platform: 'Any CPU'
    configuration: 'Release'

- task: VSBuild@1
  displayName: 'Build B Library'
  inputs:
    solution: 'B/B/B.sln'
    msbuildArgs: '/p:DeployOnBuild=true 
                  /p:WebPublishMethod=Package 
                  /p:PackageAsSingleFile=true 
                  /p:SkipInvalidConfigurations=true 
                  /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" 
                  /p:DeployIisAppPath="Default Web Site"'
    platform: 'Any CPU'
    configuration: 'Release'

- publish: $(System.DefaultWorkingDirectory)/B/B/B/bin/Release/B.dll
  artifact: BDll

'''

1 个答案:

答案 0 :(得分:0)

从问题中的linked doc来看,引起问题的原因是在.NET Framework 3.5版和更早版本中,如果从远程位置加载程序集,则该程序集将部分运行受授予集信任,该授予集取决于加载它的区域。如果您尝试在.NET Framework 4和更高版本中运行该程序集,则会引发异常。

您可以将此行添加到您的 config 文件中:

<configuration> <runtime> <loadFromRemoteSources enabled="true"/> </runtime> </configuration>

如果要定位.NET Framework 4.6.2,则可以在 YMAL msbuildArgs中添加以下行:

/p:TargetFrameworkVersion="v4.6.2"

如果不添加此行,则在构建时它将使用默认的旧.NET Framework。

相关问题