Skip to content

Commit f93aacc

Browse files
authored
Support runtime compilation for single file application
Our runtime DLL compilation was broken for single file application.
1 parent cab02a9 commit f93aacc

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/VirtualDesktop/Interop/ComInterfaceAssemblyBuilder.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.IO;
55
using System.Linq;
66
using System.Reflection;
7+
using System.Reflection.Metadata;
78
using System.Runtime.Loader;
89
using System.Text;
910
using System.Text.RegularExpressions;
@@ -161,7 +162,20 @@ private Assembly Compile(IEnumerable<string> sources)
161162
var references = AppDomain.CurrentDomain.GetAssemblies()
162163
.Concat(new[] { Assembly.GetExecutingAssembly(), })
163164
.Where(x => x.IsDynamic == false)
164-
.Select(x => MetadataReference.CreateFromFile(x.Location));
165+
.Select(x => {
166+
if (!string.IsNullOrEmpty(x.Location))
167+
{
168+
return MetadataReference.CreateFromFile(x.Location);
169+
}
170+
else
171+
{
172+
unsafe
173+
{
174+
x.TryGetRawMetadata(out byte* blob, out int length);
175+
return AssemblyMetadata.Create(ModuleMetadata.CreateFromMetadata((IntPtr)blob, length)).GetReference();
176+
}
177+
}
178+
});
165179
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
166180
var compilation = CSharpCompilation.Create(name)
167181
.WithOptions(options)

src/VirtualDesktop/VirtualDesktop.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<Title>Virtual Desktop API for C#</Title>
2424
<RepositoryType>git</RepositoryType>
2525
<PackageReleaseNotes>$(PublishReleaseNotes)</PackageReleaseNotes>
26+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2627
</PropertyGroup>
2728

2829
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-windows10.0.19041.0|AnyCPU'">

0 commit comments

Comments
 (0)