eXpandFramework / eXpand

DevExpress XAF (eXpressApp) extension framework. 𝗹𝗶𝗻𝗸𝗲𝗱𝗶𝗻.𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸.𝗰𝗼𝗺, 𝘆𝗼𝘂𝘁𝘂𝗯𝗲.𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸.𝗰𝗼𝗺 and 𝘁𝘄𝗶𝘁𝘁𝗲𝗿 @𝗲𝘅𝗽𝗮𝗻𝗱𝗳𝗿𝗮𝗺𝗲𝘄𝗼𝗿𝗸 and or simply 𝗦𝘁𝗮𝗿/𝘄𝗮𝘁𝗰𝗵 this repository and get notified from 𝗚𝗶𝘁𝗛𝘂𝗯
http://expand.expandframework.com
Microsoft Public License
221 stars 115 forks source link

Build problems VersionConverter #380

Closed CWolffIF closed 5 years ago

CWolffIF commented 5 years ago

Hi,

I got often Errors building my project, cause the VersionConvertrer is used by another process. The VersionConverter is installed in every Sub-Project (Module, Module-Win, Win). Is this correct?

C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : New-Object : Ausnahme beim Aufrufen von ".ctor" mit 2 Argument(en): "Der Prozess kann nicht auf die Datei 2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : "C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.snk" zugreifen, da sie von einem anderen 2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : Prozess verwendet wird." 2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : In C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.ps1:108 Zeichen:18

2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : + ... $f = New-Object FileStream("$root\Xpand.snk", [FileMode]::Open ... 2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : + ~~~~~~~~~~~~~ 2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException 2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error : + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand 2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error :
2>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.targets(4,9): error MSB3073: Der Befehl "powershell.exe –NonInteractive –ExecutionPolicy Unrestricted –command "& { &'C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.11\build\Xpand.VersionConverter.ps1' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\iXISXRM.Module.csproj' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\bin\Debug\' } "" wurde mit dem Code 1 beendet.

apobekiaris commented 5 years ago

The VersionConverter is a dependency for the DevExpress.XAF modules. it installs with them.

Is there something special with your build? you build from vs? is it on parallel?

apobekiaris commented 5 years ago

hmm looks like the VersionConverter still uses resources even if there is no patching. Can you replace the Xpand.VersionConverter.ps1 from your packages folder.

using namespace System
using namespace System.IO
using namespace System.IO.Compression
using namespace System.Reflection
using namespace System.Text.RegularExpressions
using namespace Mono.Cecil
using namespace Mono.Cecil.pdb
param(
    [parameter(Mandatory)]
    [string]$projectFile,
    [parameter(Mandatory)]
    [string]$targetPath,
    [string]$referenceFilter = "DevExpress*",
    [string]$assemblyFilter = "Xpand.XAF.*"
)

$ErrorActionPreference = "Stop"
set-location $targetPath
# $VerbosePreference="Continue"
Write-Verbose "Running Version Converter on project $projectFile with target $targetPath"
$projectFileInfo = Get-Item $projectFile
[xml]$csproj = Get-Content $projectFileInfo.FullName
$references = $csproj.Project.ItemGroup.Reference
$dxReferences = $references | Where-Object { $_.Include -like "$referenceFilter" }
$root = $PSScriptRoot
"Loading Mono.Cecil"
$monoPath = "$root\mono.cecil.0.10.3\lib\net40"
if (!(Test-Path "$monoPath\Mono.Cecil.dll")) {
    $client = New-Object System.Net.WebClient
    $client.DownloadFile("https://www.nuget.org/api/v2/package/Mono.Cecil/0.10.3", "$root\mono.cecil.0.10.3.zip")
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    [ZipFile]::ExtractToDirectory("$root\mono.cecil.0.10.3.zip", "$root\mono.cecil.0.10.3")
}

[Assembly]::Load([File]::ReadAllBytes("$monoPath\Mono.Cecil.dll")) | Out-Null
[Assembly]::Load([File]::ReadAllBytes("$monoPath\Mono.Cecil.pdb.dll")) | Out-Null
Add-Type @"
using Mono.Cecil;
public class MyDefaultAssemblyResolver : DefaultAssemblyResolver{

    public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters){
        try{
            return base.Resolve(name, parameters);
        }
        catch (AssemblyResolutionException){
            var assemblyDefinition = AssemblyDefinition.ReadAssembly(string.Format(@"$targetPath\{0}.dll", name.Name));
            return assemblyDefinition;
        }
    }
}
"@ -ReferencedAssemblies @("$monoPath\Mono.Cecil.dll")
$devExpressAssemblyName = Invoke-Command {

    Write-Verbose "Finding DX assembly name"
    $dxAssemblyPath = Get-ChildItem $targetPath "$referenceFilter*.dll" | Select-Object -First 1
    if ($dxAssemblyPath) {
        $dxAssembly = [AssemblyDefinition]::ReadAssembly($dxAssemblyPath.FullName)
        Write-Verbose "$($dxAssembly.Name.Name) found from $($dxAssemblyPath.FullName)"
        $dxAssembly.Name
    }
    else {
        $name = ($dxReferences | Where-Object { $_.Include -like "*Version*" } | Select-Object -First 1).Include
        New-Object System.Reflection.AssemblyName($name)
    }
} | Select-Object -last 1
if (!$devExpressAssemblyName) {
    throw "Cannot find $referenceFilter version in $($projectFileInfo.Name)"
}

$references | Where-Object { $_.Include -like $assemblyFilter } | ForEach-Object {
    "$targetPath\$([Path]::GetFileName($_.HintPath))", "$($projectFileInfo.DirectoryName)\$($_.HintPath)" | ForEach-Object {
        if (Test-Path $_) {
            $modulePath = (Get-Item $_).FullName
            $readerParams = New-Object ReaderParameters
            $readerParams.ReadWrite = $true
            $readerParams.AssemblyResolver=New-Object MyDefaultAssemblyResolver
            $readerParams.SymbolReaderProvider = New-Object PdbReaderProvider
            $readerParams.ReadSymbols = $true
            $moduleAssembly = [AssemblyDefinition]::ReadAssembly($modulePath, $readerParams)
            Write-Verbose "Checking $modulePath references.."
            $moduleAssembly.MainModule.AssemblyReferences.ToArray() | Write-Verbose
            $needPatching=$false
            $moduleAssembly.MainModule.AssemblyReferences.ToArray() | Where-Object { $_.FullName -like $referenceFilter } | ForEach-Object {
                $nowReference = $_
                Write-Verbose "Checking $_ reference..."
                if ($nowReference.Version -ne $devExpressAssemblyName.Version) {
                    $moduleAssembly.MainModule.AssemblyReferences.Remove($nowReference)
                    $newMinor = "$($devExpressAssemblyName.Version.Major).$($devExpressAssemblyName.Version.Minor)"
                    $newName = [Regex]::Replace($nowReference.Name, ".(v[\d]{2}\.\d)", ".v$newMinor")
                    $regex = New-Object Regex("PublicKeyToken=([\w]*)")
                    $token = $regex.Match($nowReference).Groups[1].Value
                    $regex = New-Object Regex("Culture=([\w]*)")
                    $culture = $regex.Match($nowReference).Groups[1].Value
                    $newReference = [AssemblyNameReference]::Parse("$newName, Version=$($devExpressAssemblyName.Version), Culture=$culture, PublicKeyToken=$token")
                    $moduleAssembly.MainModule.AssemblyReferences.Add($newreference)
                    $moduleAssembly.MainModule.Types | ForEach-Object {
                        $moduleAssembly.MainModule.GetTypeReferences() | Where-Object { $_.Scope -eq $nowReference } |ForEach-Object { 
                            $_.Scope = $newReference 
                        }
                    }
                    Write-Verbose "$($_.Name) version changed from $($_.Version) to $($devExpressAssemblyName.Version)" 
                    $needPatching=$true
                }
                else {
                    Write-Verbose "Versions ($($nowReference.Version)) matched nothing to do."
                }
            }
            if ($needPatching){
                $writeParams = New-Object WriterParameters
                $writeParams.WriteSymbols=$true
                $f = New-Object FileStream("$root\Xpand.snk", [FileMode]::Open)
                $writeParams.StrongNameKeyPair = New-Object System.Reflection.StrongNameKeyPair ( $f)
                $moduleAssembly.Write($writeParams)
                $f.Dispose()
            }

            $moduleAssembly.Dispose()   
        }
    }
}
apobekiaris commented 5 years ago

now it will only go to the exception line if patching is to be done which is determined by looking the nugets installation folder.

let me know if this relaxed the problem, or should I try the mutext approach as well.

expand commented 5 years ago

The DevExpress.XAF repository includes commit Update Build Version to ALl #380,VersionConverter: Does not release resources on error #380 that relate to this task. Please update the related Nuget packages and test if issues is addressed. These are nightly nuget packages available only from our NugetServer.

Thanks a lot for your contribution.

CWolffIF commented 5 years ago

Thanks, it works.

CWolffIF commented 5 years ago

Sorry,

but now is the problem in the Reactive Module.

C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : ForEach-Object : Ausnahme beim Aufrufen von "ReadAssembly" mit 2 Argument(en): "Der Prozess kann nicht auf die Datei 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : "C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module.Win\bin\Debug\Xpand.XAF.Modules.Reactive.dll" zugreifen, da sie von 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : einem anderen Prozess verwendet wird." 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : In C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.ps1:87 Zeichen:109 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : + ... "$($projectFileInfo.DirectoryName)\$($_.HintPath)" | ForEach-Object { 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : + ~~~~ 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : + CategoryInfo : NotSpecified: (:) [ForEach-Object], MethodInvocationException 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error : + FullyQualifiedErrorId : IOException,Microsoft.PowerShell.Commands.ForEachObjectCommand 4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error :
4>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.targets(4,9): error MSB3073: Der Befehl "powershell.exe –NonInteractive –ExecutionPolicy Unrestricted –command "& { &'C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.ps1' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module.Win\iXISXRM.Module.Win.csproj' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module.Win\bin\Debug\' } "" wurde mit dem Code 1 beendet.

apobekiaris commented 5 years ago

do u see a way of reproducing it?

apobekiaris commented 5 years ago

Der Prozess kann nicht auf die Datei

this is a side effect of a previous exception, can you uncomment this line https://github.com/eXpandFramework/DevExpress.XAF/blob/70f60fc02517ddaf180cd00c5a9c8cbc38b6824a/tools/Xpand.VersionConverter/Xpand.VersionConverter.ps1#L16 in your C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.13\build\Xpand.VersionConverter.ps1 and report back the VS output window contents the first time the error occurred

apobekiaris commented 5 years ago

please update your packages, i belive all your issues are addressed

apobekiaris commented 5 years ago

apologies the problem is still here, but I managed to reproduce it, soon will have a patch.

apobekiaris commented 5 years ago

the workaround until the patch is to disable parallel builds

image

expand commented 5 years ago

The DevExpress.XAF repository includes commit Cross process patching synchronization #380,DevExpress version is not resolved #380,Destroy AppDomain to release resource #380 that relate to this task. Please update the related Nuget packages and test if issues is addressed. These are nightly nuget packages available only from our NugetServer.

Thanks a lot for your contribution.

apobekiaris commented 5 years ago

Unfortunately I couldn't find a way to repro the issue. Here the the steps I followed.

  1. Install eXpandFramework in GAC

    Set-ExecutionPolicy Bypass -Scope Process -Force;iex "$(([System.Net.WebClient]::new()).DownloadString('http://install.expandframework.com'));Install-Xpand -Assets @('Assemblies','Nuget','VSIX','Source')  #-Version '18.2.704.0'"
  2. Create a new XAF empty solution and open VS package manager console and type:

  3. Install XpandPosh

    Install-Module XpandPosh -MinimumVersion 1.9.5
  4. Update to 4.6.1 as I wanted to install all modules.

    Update-ProjectTargetFramework
  5. Install all packages

    Find-XpandPackage Xpand*|Install-Packge
  6. Register the installed packages by paste the next snippet in the constructor of my agnostic module as instructed by readme.

            RequiredModuleTypes.Add(typeof(Xpand.XAF.Modules.ViewEditMode.ViewEditModeModule));
            RequiredModuleTypes.Add(typeof(Xpand.XAF.Modules.SuppressConfirmation.SupressConfirmationModule));
            RequiredModuleTypes.Add(typeof(Xpand.XAF.Modules.ModelViewInheritance.ModelViewInheritanceModule));
            RequiredModuleTypes.Add(typeof(Xpand.XAF.Modules.MasterDetail.MasterDetailModule));
            RequiredModuleTypes.Add(typeof(Xpand.XAF.Modules.CloneModelView.CloneModelViewModule));
            RequiredModuleTypes.Add(typeof(Xpand.XAF.Modules.CloneMemberValue.CloneMemberValueModule));
            RequiredModuleTypes.Add(typeof(Xpand.XAF.Modules.AutoCommit.AutoCommitModule));
  7. Build the solution which failed in the first build complaining about a conflict in the system.valuetuple and suggesting to Enable Automatic Binding redirection in the properties of my csproject.

  8. Build again and open VS designer with no errors.

apobekiaris commented 5 years ago

for this I use the latest standalone packages from the lab which I will publish official soon.

expand commented 5 years ago

eXpand.lab release 18.2.703.10 includes commit Update XAF modules nugets #380 that relate to this task. Please test if it addresses the problem. If you use nuget add our LAB NugetServer as a nuget package source in VS.

Thanks a lot for your contribution.

CWolffIF commented 5 years ago

Hi Tolis,

I did everything like your instruction. But now I can´t build a Project anymore.

C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : Cannot find DevExpress Version C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : In C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.ps1:191 Zeichen:5 C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + throw $_.Exception C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + ~~~~~~ C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + FullyQualifiedErrorId : RuntimeException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error :
C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error MSB3073: Der Befehl "powershell.exe –NonInteractive –ExecutionPolicy Unrestricted –command "& { &'C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.ps1' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\iXISXRM.Module.csproj' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\bin\Debug\' } "" wurde mit dem Code 1 beendet.

CWolffIF commented 5 years ago

Hi,

I switched back to VersionConverter.1.0.16 (and the other Xpand.Modules) and I can compile.

apobekiaris commented 5 years ago

C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : Cannot find DevExpress Version C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : In C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.ps1:191 Zeichen:5 C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + throw $_.Exception C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + ~~~~~~ C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + FullyQualifiedErrorId : RuntimeException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error MSB3073: Der Befehl "powershell.exe –NonInteractive –ExecutionPolicy Unrestricted –command "& { &'C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.ps1' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\iXISXRM.Module.csproj' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\bin\Debug' } "" wurde mit dem Code 1 beendet.

the cross cross process patch synchronization introduced in 1.0.17, and was required not only for this case but also for FeatureCenter as it had the same problem. This exception should be failry easy to resolve as it only about not finding which DX version to patch. So looking at the Version converter he have. https://github.com/eXpandFramework/DevExpress.XAF/blob/9ff066b84f67137f9b643ab768f9e762d4fd00c8/tools/Xpand.VersionConverter/Xpand.VersionConverter.ps1#L53-L89

  1. DX version is detected first from the csproj file references hintpath (hintpath should be valid if dx is not in gac e.g. nuget or u simply manully reference from a dir)

    $hintPath = $dxReferences.HintPath | foreach-Object { 
        if ($_) {
            $path = $_
            if (![path]::IsPathRooted($path)) {
                $path = "$((Get-Item $projectFile).DirectoryName)\$_"
            }
            if (Test-Path $path) {
            }
        }
    } | Where-Object { $_ } | Select-Object -First 1
    if ($hintPath ) {
        Write-Verbose "$($dxAssembly.Name.Name) found from $hintpath"
        Use-Object($assembly = Get-MonoAssembly $hintPath) {
            $assembly.name.version
        }
    }

    apparently for this case HintPath was null for all your dx references. (You could of course manually add in one and help detection but we want to automate it.)

  2. if hintpath fails 2nd attempt is to look in the bin directory of your project for a dx assembly and get its version

    $dxAssemblyPath = Get-ChildItem $targetPath "$referenceFilter*.dll" | Select-Object -First 1
        if ($dxAssemblyPath) {
            Write-Verbose "$($dxAssembly.Name.Name) found from $($dxAssemblyPath.FullName)"
            Use-Object($assembly = Get-MonoAssembly $dxAssemblyPath.FullName) {
                $assembly.name.version
            }
        }

    for this case apparently your bin was empty of dx assemblies, again u can put any dx assembly manual there and the exception will not throw.

  3. 3rd attempt if hintpath and bin fail is to look in the gac for any dx assembly for the major DX version found from your csproj

    $dxReference=($dxReferences|Select-Object -First 1).Include
            $dxAssembly=Get-ChildItem "$env:windir\Microsoft.NET\assembly\GAC_MSIL"  *.dll -Recurse|Where-Object{$_ -like "*$dxReference.dll"}
            if ($dxAssembly){
                Use-Object($assembly = Get-MonoAssembly $dxAssembly.FullName) {
                    $assembly.name.version
                }
            }

if all 3 fail then u get the exception u posted. But now my question is how VS finds your DX assemblies? It looks like hinpath is null gac is null and bin is empty.

apobekiaris commented 5 years ago

I think I have the answer what this script returns?

Get-ChildItem ((Get-ItemProperty -LiteralPath HKLM:\Software\Wow6432Node\Microsoft\.NETFramework\AssemblyFolders\Xpand)."(Default)") DevExpress*.dll|Select-Object -First 1
CWolffIF commented 5 years ago

Hi,

in that path there are no DevExpress*.dll.

apobekiaris commented 5 years ago

so whats the path of your DX assemblies in your project? expand the references node, select a dx assembly and post the path that displayed there?

CWolffIF commented 5 years ago

C:\Program Files (x86)\DevExpress 18.2\Components\Bin\Framework\DevExpress.ExpressApp.v18.2.dll

apobekiaris commented 5 years ago

so dx is in your gac right?

CWolffIF commented 5 years ago

Yes

apobekiaris commented 5 years ago

can u edit the csproj and post how a dx assembly reference is declared?

CWolffIF commented 5 years ago
<Reference Include="DevExpress.ExpressApp.v18.2, Version=18.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
</Reference>
apobekiaris commented 5 years ago

also verify that this query returns dx assemblies

Get-ChildItem "$env:windir\Microsoft.NET\assembly\GAC_MSIL"  DevExpress*18.2*.dll -Recurse
CWolffIF commented 5 years ago

Works

Verzeichnis: C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\DevExpress.ExpressApp.v18.2\v4.0_18.2.7.0__b88d1754d700e49a

Mode LastWriteTime Length Name


-a---- 29.04.2019 07:34 2068216 DevExpress.ExpressApp.v18.2.dll

apobekiaris commented 5 years ago

excellent wait for my next patch please I will improvwe the detection algorithm and we are set

apobekiaris commented 5 years ago

can you replace the VersionConverter.ps1 in your packages folder with this

using namespace System
using namespace System.Threading
using namespace System.Reflection
using namespace System.IO
using namespace System.IO.Compression
using namespace System.Reflection
using namespace System.Text.RegularExpressions
using namespace Mono.Cecil
using namespace Mono.Cecil.pdb
param(
    [string]$projectFile,
    [string]$targetPath,
    [string]$referenceFilter = "DevExpress*",
    [string]$assemblyFilter = "Xpand.XAF.*"
)

# $VerbosePreference = "Continue"
$ErrorActionPreference = "Stop"

function Use-Object {
    [CmdletBinding()]
    param (
        [Object]$InputObject,
        [Parameter(Mandatory = $true)]
        [scriptblock]$ScriptBlock
    )
    $killDomain
    try {
        . $ScriptBlock
    }
    catch {
        $killDomain = $true
    }
    finally {
        if ($null -ne $InputObject -and $InputObject -is [System.IDisposable]) {
            $InputObject.Dispose()
            if ($killDomain) {
                Stop-Process -id $pid
            }
        }
    }
}
function Get-MonoAssembly($path, [switch]$Write) {
    $readerParams = New-Object ReaderParameters
    if ($Write) {
        $readerParams.ReadWrite = $true
        $readerParams.SymbolReaderProvider = New-Object PdbReaderProvider
        $readerParams.ReadSymbols = $true
    }
    $readerParams.AssemblyResolver = New-Object MyDefaultAssemblyResolver
    [ModuleDefinition]::ReadModule($path, $readerParams).Assembly
}
function Get-DevExpressVersion($targetPath, $referenceFilter,$dxReferences) {
    Write-Verbose "Finding DevExpress version..."
    $hintPath = $dxReferences.HintPath | foreach-Object { 
        if ($_) {
            $path = $_
            if (![path]::IsPathRooted($path)) {
                $path = "$((Get-Item $projectFile).DirectoryName)\$_"
            }
            if (Test-Path $path) {
                [path]::GetFullPath($path)
            }
        }
    } | Where-Object { $_ } | Select-Object -First 1
    if ($hintPath ) {
        Write-Verbose "$($dxAssembly.Name.Name) found from $hintpath"
        Use-Object($assembly = Get-MonoAssembly $hintPath) {
            $assembly.name.version
        }
    }
    else {
        $dxAssemblyPath = Get-ChildItem $targetPath "$referenceFilter*.dll" | Select-Object -First 1
        if ($dxAssemblyPath) {
            Write-Verbose "$($dxAssembly.Name.Name) found from $($dxAssemblyPath.FullName)"
            Use-Object($assembly = Get-MonoAssembly $dxAssemblyPath.FullName) {
                $assembly.name.version
            }
        }
        else {
            $include=($dxReferences|Select-Object -First 1).Include
            $dxReference=$include -imatch 'DevExpress[^,]*'
            $dxAssembly=Get-ChildItem "$env:windir\Microsoft.NET\assembly\GAC_MSIL"  *.dll -Recurse|Where-Object{$_ -like "*$dxReference.dll"}
            if ($dxAssembly){
                Use-Object($assembly = Get-MonoAssembly $dxAssembly.FullName) {
                    $assembly.name.version
                }
            }
            else{
                throw "Cannot find DevExpress Version"
            }

        }
    }
}

function Update-Version($modulePath, $dxVersion) {
    Use-Object($moduleAssembly = Get-MonoAssembly $modulePath -Write) {
        $moduleReferences = $moduleAssembly.MainModule.AssemblyReferences
        Write-Verbose "References:"
        $moduleReferences | Write-Verbose
        $needPatching = $false
        $moduleReferences.ToArray() | Where-Object { $_.FullName -like $referenceFilter } | ForEach-Object {
            $dxReference = $_
            Write-Verbose "Checking $_ reference..."
            if ($dxReference.Version -ne $dxVersion) {
                $moduleReferences.Remove($dxReference)
                $newMinor = "$($dxVersion.Major).$($dxVersion.Minor)"
                $newName = [Regex]::Replace($dxReference.Name, ".(v[\d]{2}\.\d)", ".v$newMinor")
                $regex = New-Object Regex("PublicKeyToken=([\w]*)")
                $token = $regex.Match($dxReference).Groups[1].Value
                $regex = New-Object Regex("Culture=([\w]*)")
                $culture = $regex.Match($dxReference).Groups[1].Value
                $newReference = [AssemblyNameReference]::Parse("$newName, Version=$($dxVersion), Culture=$culture, PublicKeyToken=$token")
                $moduleReferences.Add($newreference)
                $moduleAssembly.MainModule.Types | ForEach-Object {
                    $moduleAssembly.MainModule.GetTypeReferences() | Where-Object { $_.Scope -eq $dxReference } | ForEach-Object { 
                        $_.Scope = $newReference 
                    }
                }
                Write-Verbose "$($_.Name) version will changed from $($_.Version) to $($dxVersion)" 
                $needPatching = $true
            }
            else {
                Write-Verbose "Versions ($($dxReference.Version)) matched nothing to do."
            }
        }
        if ($needPatching) {
            Write-Verbose "Patching $modulePath"
            $writeParams = New-Object WriterParameters
            $writeParams.WriteSymbols = $true
            $key = [byte[]]::new(0)
            $key = [File]::ReadAllBytes("$root\Xpand.snk")
            $writeParams.StrongNameKeyPair = [System.Reflection.StrongNameKeyPair]($key)
            $moduleAssembly.Write($writeParams)
        }   
    }
}
try {
    $mtx = [Mutex]::OpenExisting("VersionConverterMutex")
}
catch {
    $mtx = [Mutex]::new($true, "VersionConverterMutex")
}

try {
    set-location $targetPath
    Write-Verbose "Running Version Converter on project $projectFile with target $targetPath"
    $projectFileInfo = Get-Item $projectFile
    [xml]$csproj = Get-Content $projectFileInfo.FullName
    $references = $csproj.Project.ItemGroup.Reference
    $dxReferences = $references | Where-Object { $_.Include -like "$referenceFilter" }
    $root = $PSScriptRoot
    Write-Verbose "Loading Mono.Cecil"
    $monoPath = "$root\mono.cecil.0.10.3\lib\net40"
    if (!(Test-Path "$monoPath\Mono.Cecil.dll")) {
        $client = New-Object System.Net.WebClient
        $client.DownloadFile("https://www.nuget.org/api/v2/package/Mono.Cecil/0.10.3", "$root\mono.cecil.0.10.3.zip")
        Add-Type -AssemblyName System.IO.Compression.FileSystem
        [ZipFile]::ExtractToDirectory("$root\mono.cecil.0.10.3.zip", "$root\mono.cecil.0.10.3")
    }

    [System.Reflection.Assembly]::Load([File]::ReadAllBytes("$monoPath\Mono.Cecil.dll")) | Out-Null
    [System.Reflection.Assembly]::Load([File]::ReadAllBytes("$monoPath\Mono.Cecil.pdb.dll")) | Out-Null
    Add-Type @"
using Mono.Cecil;
public class MyDefaultAssemblyResolver : DefaultAssemblyResolver{
    public override AssemblyDefinition Resolve(AssemblyNameReference name, ReaderParameters parameters){
        try{
            return base.Resolve(name, parameters);
        }
        catch (AssemblyResolutionException){
            var assemblyDefinition = AssemblyDefinition.ReadAssembly(string.Format(@"$targetPath\{0}.dll", name.Name));
            return assemblyDefinition;
        }
    }
}
"@ -ReferencedAssemblies @("$monoPath\Mono.Cecil.dll")

    $dxVersion = Get-DevExpressVersion $targetPath $referenceFilter $dxReferences
    $references | Where-Object { $_.Include -like $assemblyFilter } | ForEach-Object {
        "$targetPath\$([Path]::GetFileName($_.HintPath))", "$($projectFileInfo.DirectoryName)\$($_.HintPath)" | ForEach-Object {
            if (Test-Path $_) {
                $modulePath = (Get-Item $_).FullName
                Write-Verbose "Checking $modulePath references.."
                Update-Version $modulePath $dxVersion
            }
        }
    }
}
catch {
    throw $_.Exception
}
finally {
    $mtx.ReleaseMutex()
    $mtx.Dispose()
}

and let me know if it works, also delete all XPand* folders inside the Packages folder except versionconverter of course so that they will patched again.

CWolffIF commented 5 years ago

Hi Tolis,

I patched all to the new version from nuget.org and than replaced the VersionConverter.ps1 Code.

It works and has many "true"......

------ Erstellen gestartet: Projekt: iXISFramework.Module.Win, Konfiguration: Debug Any CPU ------ True True True True True True True True True True True True True True True True True True C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module.Win\Controllers\IFLockController.cs(40,30,40,32): warning CS0168: Die Variable "ex" ist deklariert, wird aber nie verwendet. iXISFramework.Module.Win -> C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module.Win\bin\Debug\iXISFramework.Module.Win.dll

apobekiaris commented 5 years ago

true is for each patched references i will hide it, thnks for testing!

wait for the official and update.

CWolffIF commented 5 years ago

Hi Tolis,

actual I "...the workaround until the patch is to disable parallel builds.." set to 1. If I set then back to 8, I got following error message:

4>------ Erstellen gestartet: Projekt: iXISFramework.Module.Win, Konfiguration: Debug Any CPU ------ 3> True 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : Ausnahme beim Aufrufen von "ReleaseMutex" mit 0 Argument(en): "Die Objektsynchronisationsmethode wurde von einem 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : nicht synchronisierten Codeblock aufgerufen." 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : In C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.ps1:195 Zeichen:5 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + $mtx.ReleaseMutex() 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + ~~~~~~~ 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error : + FullyQualifiedErrorId : ApplicationException 3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error :
3>C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.targets(4,9): error MSB3073: Der Befehl "powershell.exe –NonInteractive –ExecutionPolicy Unrestricted –command "& { &'C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.17\build\Xpand.VersionConverter.ps1' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\iXISXRM.Module.csproj' 'C:\DevProjects\iXISJH\iXISXRM\iXISXRM.Module\bin\Debug\' } "" wurde mit dem Code 1 beendet.

apobekiaris commented 5 years ago

hmm this smells some kind of mistake following all my directions, let's go for a lab build to make sure everything is setup ok. Please update the packages when the bot notifies.

apobekiaris commented 5 years ago

I guess you can consume lab builds right? you setup the lab package source in your vs already?

CWolffIF commented 5 years ago

The lab nugets are at https://xpandnugetserver.azurewebsites.net/nuget right?

apobekiaris commented 5 years ago

yes

expand commented 5 years ago

The DevExpress.XAF repository includes commit Improve Dx verions detection algorithm #380 that relate to this task. Please update the related Nuget packages and test if issues is addressed. These are nightly nuget packages available only from our NugetServer.

Thanks a lot for your contribution.

apobekiaris commented 5 years ago

sorry this a bad release do not use it wait for the next one

expand commented 5 years ago

The DevExpress.XAF repository includes commit Improve Dx verions detection algorithm #380 that relate to this task. Please update the related Nuget packages and test if issues is addressed. These are nightly nuget packages available only from our NugetServer.

Thanks a lot for your contribution.

apobekiaris commented 5 years ago

this a good release

CWolffIF commented 5 years ago

Hi Tolis,

something went wrong. The actual Lab Version of the VersionConverter is 1.0.18 (29.04.2019 16:51) and the error is back. But the Code from above doesn´t work anymore.

C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : Cannot find DevExpress Version C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : In C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.ps1:192 Zeichen:5 C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + throw $_.Exception C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + ~~~~~~ C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + FullyQualifiedErrorId : RuntimeException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error :
C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error MSB3073: Der Befehl "powershell.exe –NonInteractive –ExecutionPolicy Unrestricted –command "& { &'C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.ps1' 'C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module\iXISFramework.Module.csproj' 'C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module\bin\Debug\' } "" wurde mit dem Code 1 beendet.

apobekiaris commented 5 years ago

Hi,

with some patient we can find what is happening here.

I see my changes are distributed ok https://github.com/eXpandFramework/DevExpress.XAF/blob/bad2bbdd30e6c9dc07b4110f1c71585d27e70c35/tools/Xpand.VersionConverter/Xpand.VersionConverter.ps1#L81-L82

to test why it does not find it in gac please modify the VersionCOnverter.ps1

  1. Uncomment ln 17 to enable verbose messaging
  2. Insert after ($dxReference=$include -imatch 'DevExpress[^,]*') which is in ln 82
    Write-Verbose "Include=$Include"
    Write-Verbose "DxReference=$dxReference"
  3. Remove Xpand.XAF.* folders from the Packages Rebuild and post the output
apobekiaris commented 5 years ago

also note that Xpand lab pass fine. Especially FeatureCenter uses multiple packages over 12 parallel jobs so we have an indicator that we are on the right path.

CWolffIF commented 5 years ago

Hi,

what do you mean with "3. Remove Xpand.XAF.* folders from the Packages Rebuild and post the output"?

the output after 1. and 2. is

AUSFÜHRLICH: Running Version Converter on project C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module\iXISFramework.Module.csproj with target C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module\bin\Debug\ AUSFÜHRLICH: Loading Mono.Cecil AUSFÜHRLICH: Finding DevExpress version... AUSFÜHRLICH: Include=DevExpress.Data.v18.2, Version=18.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL AUSFÜHRLICH: DxReference=True C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : Cannot find DevExpress Version C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : In C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.ps1:196 Zeichen:5 C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + throw $_.Exception C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + ~~~~~~ C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error : + FullyQualifiedErrorId : RuntimeException C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error :
C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.targets(4,9): error MSB3073: Der Befehl "powershell.exe –NonInteractive –ExecutionPolicy Unrestricted –command "& { &'C:\DevProjects\NuGetPackages\Xpand.VersionConverter.1.0.18\build\Xpand.VersionConverter.ps1' 'C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module\iXISFramework.Module.csproj' 'C:\DevProjects\iXISJH\iXISXRM\iXISFramework.Module\bin\Debug\' } "" wurde mit dem Code 1 beendet.

apobekiaris commented 5 years ago

Inside the Packages folder there are Xpand.XAF.* folders for each package you installed. The assemblies might be already patched so the code won't reach the line in question. Removing them will and Rebuild will assure patching again.

apobekiaris commented 5 years ago

you might also want to clear your local nuget cache in this machine, just in case God is laughing with us

& nuget.exe locals all -clear

or if you have XPandPOsh installed just do

Clear-NugetCache
CWolffIF commented 5 years ago

Hi,

OK I cleared everything. I checked the lines 80+ with some messages

$include=($dxReferences|Select-Object -First 1).Include $dxReference=$include -imatch 'DevExpress[^,]*'

        Write-Verbose "Include=$Include"
        Write-Verbose "DxReference=$dxReference"

        $dxAssembly=Get-ChildItem "$env:windir\Microsoft.NET\assembly\GAC_MSIL"  *.dll -Recurse|Where-Object{$_ -like "*$dxReference.dll"}
        Write-Verbose "ifaktor 1"

        if ($dxAssembly){
                    Write-Verbose "ifaktor 2"
            Use-Object($assembly = Get-MonoAssembly $dxAssembly.FullName) {
                                    Write-Verbose "ifaktor 3"
                $assembly.name.version
            }
        }
        else{
                    Write-Verbose "ifaktor else"
            throw "Cannot find DevExpress Version"
        }

The Output is AUSFÜHRLICH: Loading Mono.Cecil AUSFÜHRLICH: Finding DevExpress version... AUSFÜHRLICH: Include=DevExpress.Data.v18.2, Version=18.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL AUSFÜHRLICH: DxReference=True AUSFÜHRLICH: ifaktor 1 AUSFÜHRLICH: ifaktor else

It did not go to Write-Verbose "ifaktor 2" so the if ($dxAssembly)

CWolffIF commented 5 years ago

I think the $dxAssembly is null

CWolffIF commented 5 years ago

$dxReference is true (boolean) so $dxAssembly=Get-ChildItem "$env:windir\Microsoft.NET\assembly\GACMSIL" *.dll -Recurse|Where-Object{$ -like "*$dxReference.dll"} is null