Azure-Player / azure.datafactory.tools

Tools for deploying Data Factory (v2) in Microsoft Azure
https://azureplayer.net/adftools
MIT License
207 stars 69 forks source link

`Publish-AdfV2FromJson` cannot be executed without manually loading classes in my environment #337

Closed fmms closed 1 year ago

fmms commented 1 year ago

Describe the bug Thank you for the awesome tool!

When executing the tool out of the box it does not work for me but complains about missing types.

PS C:\df-gamdwh-ingest-fm> Publish-AdfV2FromJson -RootFolder "C:\df-gamdwh-ingest-fm" -ResourceGroupName "rg-gamdwh-prod
-001" -DataFactoryName "df-gamdwh-ingest-prod" -Location "West Europe" -Option $opt -Stage .\deployment\prod.csv
======================================================================================
### azure.datafactory.tools                                       Version 1.5.000 ###
======================================================================================
Invoking Publish-AdfV2FromJson (https://github.com/SQLPlayer/azure.datafactory.tools)
with the following parameters:
======================================================================================
RootFolder:         C:\df-gamdwh-ingest-fm
ResourceGroupName:  rg-gamdwh-prod-001
DataFactoryName:    df-gamdwh-ingest-prod
Location:           West Europe
Stage:              .\deployment\prod.csv
Options provided:   True
Publishing method:  AzResource
Is Dry Run?:        False
======================================================================================
Options:

Includes                       : {}
Excludes                       : {}
DeleteNotInSource              : True
StopStartTriggers              : True
CreateNewInstance              : True
DeployGlobalParams             : True
FailsWhenConfigItemNotFound    : True
FailsWhenPathNotFound          : True
IgnoreLackOfReferencedObject   : False
DoNotStopStartExcludedTriggers : False
DoNotDeleteExcludedObjects     : True
IncrementalDeployment          : False

======================================================================================
Der Typ [AdfDeploymentState] wurde nicht gefunden.
In \\mnzfs100\Users-Ext$\xmoell46\WindowsPowerShell\Modules\azure.datafactory.tools\1.5.0\public\Publish-AdfV2FromJson.
ps1:134 Zeichen:18
+     $script:ds = [AdfDeploymentState]::new($verStr)
+                  ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (AdfDeploymentState:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

To Reproduce I have created the following hack to be able to use the tool

$psmodulebase=$($env:PSModulePath -split ";" | select -First 1)
$adtclassbase=$(Join-Path $psmodulebase "azure.datafactory.tools\1.5.0\private")
. "$adtclassbase\Adf.class.ps1"
. "$adtclassbase\DeploymentState.class.ps1"
. "$adtclassbase\AdfObject.class.ps1"
. "$adtclassbase\!AdfPublishOption.class.ps1"
. "$adtclassbase\AdfObjectName.class.ps1"
. "$adtclassbase\Get-SimplifiedType.ps1"
. "$adtclassbase\Get-AzureResourceType.ps1"

$opt = New-AdfPublishOption
$opt.DeleteNotInSource = $true

Publish-AdfV2FromJson -RootFolder "C:\df-gamdwh-ingest-fm" -ResourceGroupName "rg-gamdwh-prod-001" -DataFactoryName "df-gamdwh-ingest-prod" -Location "West Europe" -Option $opt -Stage .\deployment\prod.csv

Expected behaviour A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Version of PowerShell module of:

PS C:\df-gamdwh-ingest-fm> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.5582
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.5582
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\df-gamdwh-ingest-fm> Get-Module Azure.datafactory.tools

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.5.0      azure.datafactory.tools             {Export-AdfToArmTemplate, Get-AdfDocDiagram, Get-AdfFromService, Import-AdfFromFolder...}

Provide all files to reproduce the issue

NowinskiK commented 1 year ago

Use the following code to load all classes and commands locally: https://github.com/Azure-Player/azure.datafactory.tools/blob/6844dee2f81264cb1e9a345970c42e5ef890299f/adhoc/issue-279/test-279.ps1#L7C1-L7C66

fmms commented 1 year ago

@NowinskiK just to clarify. Is it correct that I have to execute the above code, even though that I have installed the azure.datafactory.tools with

```ps
Install-Module -Name azure.datafactory.tools -Scope CurrentUser
Install-Module -Name Az.DataFactory -MinimumVersion "1.10.0" -Scope CurrentUser
Install-Module -Name Az.Resources -Scope CurrentUser
Import-Module -Name azure.datafactory.tools

I assumed this is only needed if I run the tools from a github clone?

NowinskiK commented 1 year ago

No, installation and import of the module is completely sufficient to run any public command. Try to restart your PS session.