How to Specify .NET Framework Version in YAML Pipeline?

4.4k Views Asked by At

I'm extremely new to YAML--I'm trying to update a plug-in library using the published artifact DLL from build B (see YAML below) however I keep receiving the following error:

enter image description here

How can I specify the .NET Framework in the YAML so that it is not trying to use an old version? I need it to use 4.6.2. I've browsed every Microsoft Doc and found that you can specify it running tests but have had zero luck trying to find how to set it for a build.

Just to clarify, the YAML below successfully runs and I can download the DLL but upon updating the plug-in registration it will result in the error.

'''

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

There are 1 best solutions below

0
On

From the linked doc in the issue, the cause of the issue is that In the .NET Framework version 3.5 and earlier versions, if you loaded an assembly from a remote location, the assembly would run partially trusted with a grant set that depended on the zone in which it was loaded. If you try to run that assembly in the .NET Framework version 4 and later versions, an exception is thrown.

You can add this line in your config file:

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

If you want to target .NET Framework 4.6.2, you can add this line in the msbuildArgs of YMAL:

/p:TargetFrameworkVersion="v4.6.2"

If you don't add this line, it will use the default old .NET Framework when build.