Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DACPAC updated returns on error on VS2022/.NET 4.8 based hosted agents #1592

Closed
rfennell opened this issue Mar 4, 2024 · 2 comments
Closed
Assignees

Comments

@rfennell
Copy link
Owner

rfennell commented Mar 4, 2024

Azure DevOps Extensions

Manifest Versioning

Platform

Azure DevOps Services

Azure DevOps Server (TFS) Version

No response

Extension Version

DACPAC updater

Describe the bug

When the DACPAC task is run on a current Microsoft hosted agent (VS2022 and .NET 4.8) the following error is seen

No user provided ToolPath, so searching default locations
Scan standard Visual Studio locations (2017 and later)
Found the newest SDK in 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\SQLDB\DAC'
##[error]Exception calling "LoadFromDacpac" with "2" argument(s): "Could not load file or assembly 'System.Resources.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified."

Repo Steps

Use the task on a current hosted build agent

Expected Behavior

The version should be set without error

Logging Information

No response

@rfennell
Copy link
Owner Author

rfennell commented Mar 4, 2024

I think the issue is related to issue dotnet/runtime#39078.

When the script (within the tasks) is tested locally on PowerShell V5 I can get the same error, but if I run script the twice it works the 2nd time

function Update-DacpacVerion {
    param(
        [parameter(Mandatory)]
        [String]$Path,

        [Parameter(Mandatory)]
        [System.Version]$VersionNumber,

        [string]$ToolPath

    )

    #Specifying the Error Preference within the function scope to help catch errors
    $ErrorActionPreference = 'Stop'

    # Add SQL methods from Dlls, using Test-Path to determine which version to import based on VS version
    try {
        Add-Type -Path "$ToolPath\Microsoft.SqlServer.Dac.Extensions.dll"
        Add-Type -Path "$ToolPath\Microsoft.SqlServer.Dac.dll"
    }
    catch {
        Write-Error 'Failed to load DLL, check all SDKs and SSDT are installed correctly in the Visual Studio folders.'
        Exit -1
    }

    #Loads the DacPac ready for updating
    $StorageType = [Microsoft.SqlServer.Dac.DacSchemaModelStorageType]::File
    $AccessType = [System.IO.FileAccess]::ReadWrite
    $DacPacObject = [Microsoft.SqlServer.Dac.DacPackage]::Load($Path, $StorageType, $AccessType)

    #Sets up various load options for updating dacpac
    $LoadOptions = New-Object Microsoft.SqlServer.Dac.Model.ModelLoadOptions($null)
    $LoadOptions.LoadAsScriptBackedModel = $true
    $LoadOptions.ModelStorageType = $StorageType
    $TSQLModel = [Microsoft.SqlServer.Dac.Model.TSqlModel]::LoadFromDacpac($Path, $LoadOptions)

    #sets up details to update in dacpac
    $DacpacOptions = New-Object Microsoft.SqlServer.Dac.PackageMetadata($null)
    $DacpacOptions.Description = $DacPacObject.Description
    $DacpacOptions.Name = $DacPacObject.Name
    $DacpacOptions.Version = $VersionNumber

    Try {
        Write-Verbose "Attempting to update $($DacPacObject.Name) with version number $VersionNumber" -Verbose
        #Updates the DacPack with specified details
        [Microsoft.SqlServer.Dac.DacPackageExtensions]::UpdateModel($DacPacObject, $TSQLModel, $DacpacOptions)
        Write-Verbose "Succeeded in updating $($DacPacObject.Name) with version number $VersionNumber" -Verbose
    }
    catch {
        Write-Warning "Failed to update DacPac $($DacPacObject.Name), due to error:"
        Write-Warning "$($error[0])"
    }
}


Update-DacpacVerion -path "C:\projects\bm-source\ISS\Src\Expenses\BlackMarble.ISS.Database\bin\Debug\BlackMarble.ISS.Database.dacpac" -versionnumber 1.2.3.4 -toolpath 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\Extensions\Microsoft\SQLDB\DAC'

I need to get a repo on a hosted agent

rfennell added a commit that referenced this issue Mar 4, 2024
rfennell added a commit that referenced this issue Mar 4, 2024
@rfennell
Copy link
Owner Author

rfennell commented Mar 5, 2024

Fixed with a hacky workaround (a retry) in 3.7.2

@rfennell rfennell closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant