Skip to content

Commit

Permalink
set net48 as target framework Interop.MSTSCLib.dll
Browse files Browse the repository at this point in the history
  • Loading branch information
awakecoding committed Jan 9, 2024
1 parent f9a0370 commit 594f7fc
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 10 deletions.
10 changes: 9 additions & 1 deletion dotnet/AxInterop.MSTSCLib/AxInterop.MSTSCLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@

<PropertyGroup>
<AssemblyName>AxInterop.MSTSCLib</AssemblyName>
<PackageId>AxInterop.MSTSCLib</PackageId>
<Version>1.0.0.0</Version>
<OutputType>Library</OutputType>
<UseWindowsForms>true</UseWindowsForms>
<Nullable>disable</Nullable>
<GenerateAssemblyInfo>False</GenerateAssemblyInfo>
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
<OutputPath>$(CMakeOutputPath)</OutputPath>
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Windows.Forms.AxHost.TypeLibraryTimeStampAttribute">
<_Parameter1>11/09/2021 16:17:20</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

<ItemGroup>
<Reference Include="Interop.MSTSCLib">
<Private>True</Private>
Expand Down
7 changes: 0 additions & 7 deletions dotnet/AxInterop.MSTSCLib/Properties/AssemblyInfo.cs

This file was deleted.

2 changes: 1 addition & 1 deletion dotnet/AxInterop.MSTSCLib/RdpAxHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static string RdpGetAxDllPath(string axName)

public static object RdpGetClassObject(Guid clsid, string axName, string rdpExDll)
{
object? obj = null;
object obj = null;

lock (loadLock)
{
Expand Down
2 changes: 1 addition & 1 deletion dotnet/Devolutions.MsRdpEx/Devolutions.MsRdpEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<OutputPath>$(CMakeOutputPath)</OutputPath>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>True</GenerateAssemblyInfo>
<SuppressDependenciesWhenPacking>False</SuppressDependenciesWhenPacking>
<SuppressDependenciesWhenPacking>True</SuppressDependenciesWhenPacking>
</PropertyGroup>

<ItemGroup>
Expand Down
Binary file modified dotnet/Interop.MSTSCLib/Interop.MSTSCLib.dll
Binary file not shown.
71 changes: 71 additions & 0 deletions scripts/SetAssemblyTargetFramework.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
param(
[string] $AssemblyFilePath,
[string] $FrameworkName = ".NETFramework,Version=v4.8",
[string] $FrameworkDisplayName = ".NET Framework 4.8"
)

if (-Not (Test-Path $AssemblyFilePath)) {
throw "Assembly file not found at the specified path: $AssemblyFilePath"
}

$ilasm = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\ilasm.exe"
$ildasm = "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\ildasm.exe"

if (-Not (Test-Path $ilasm)) {
throw "ilasm.exe not found at the path: $ilasm"
}

if (-Not (Test-Path $ildasm)) {
throw "ildasm.exe not found at the path: $ildasm"
}

if (-Not (Get-Command -Name 'rg' -ErrorAction SilentlyContinue)) {
throw "rg (RipGrep) not found"
}

$AssemblyName = [System.IO.Path]::GetFileNameWithoutExtension($AssemblyFilePath)
$AssemblyDllFile = $AssemblyFilePath
$AssemblyIlfile = "${AssemblyName}.il"
$AssemblyResfile = "${AssemblyName}.res"
& $ildasm "/OUT=$AssemblyIlfile" /NOBAR $AssemblyDllFile

# https://learn.microsoft.com/en-us/dotnet/api/system.runtime.versioning.targetframeworkattribute

# 01 00
# 1A (26)
# 2E 4E 45 54 46 72 61 6D 65 77 6F 72 6B 2C 56 65 72 73 69 6F 6E 3D 76 34 2E 38 ".NETFramework,Version=v4.8"
# 01 00 54 0E
# 14 (20)
# 46 72 61 6D 65 77 6F 72 6B 44 69 73 70 6C 61 79 4E 61 6D 65 "FrameworkDisplayName"
# 12 (18)
# 2E 4E 45 54 20 46 72 61 6D 65 77 6F 72 6B 20 34 2E 38 ".NET Framework 4.8"

function Convert-StringToByteArray {
param(
[Parameter(Mandatory=$true,Position=0)]
[string] $InputString
)

if ($InputString.Length -gt 255) {
throw "String length exceeds the maximum limit for a single byte."
}

$lengthByte = [byte]$InputString.Length
$utf8Bytes = [System.Text.Encoding]::UTF8.GetBytes($InputString)
return , $lengthByte + $utf8Bytes
}

$ctorBytes = @(0x01, 0x00)
$ctorBytes = $ctorBytes + (Convert-StringToByteArray $FrameworkName)
$ctorBytes = $ctorBytes + @(0x01, 0x00, 0x54, 0x0E)
$ctorBytes = $ctorBytes + (Convert-StringToByteArray "FrameworkDisplayName")
$ctorBytes = $ctorBytes + (Convert-StringToByteArray $FrameworkDisplayName)
$ctorHex = ($ctorBytes | ForEach-Object { $_.ToString("X2") }) -join " "

$lineToAdd = " .custom instance void [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::.ctor(string) = ( $CtorHex )"
$lineAfter = " .hash algorithm"
$NewContent = rg "$lineAfter" $AssemblyIlfile -r "$lineToAdd`r`n$lineAfter" -N --passthru
Set-Content -Path $AssemblyIlfile -Value $NewContent -Force

& $ilasm $AssemblyIlfile "/OUTPUT=$AssemblyDllfile" /DLL "/RESOURCE=$AssemblyResfile"
@($AssemblyIlfile, $AssemblyResfile) | Remove-Item -Force -ErrorAction SilentlyContinue

0 comments on commit 594f7fc

Please sign in to comment.