Browse Source

Merge pull request #9220 from AvaloniaUI/remove-resm-xaml-compilation

Removed deprecated XAML compiler features
Max Katz 3 years ago
parent
commit
47930aa5f0

+ 0 - 3
packages/Avalonia/AvaloniaBuildTasks.targets

@@ -3,7 +3,6 @@
     <_AvaloniaUseExternalMSBuild>$(AvaloniaUseExternalMSBuild)</_AvaloniaUseExternalMSBuild>
     <_AvaloniaUseExternalMSBuild Condition="'$(_AvaloniaForceInternalMSBuild)' == 'true'">false</_AvaloniaUseExternalMSBuild>
     <AvaloniaXamlReportImportance Condition="'$(AvaloniaXamlReportImportance)' == ''">low</AvaloniaXamlReportImportance>
-    <_AvaloniaPatchComInterop Condition="'$(_AvaloniaPatchComInterop)' == ''">false</_AvaloniaPatchComInterop>
     <_AvaloniaSkipXamlCompilation Condition="'$(_AvaloniaSkipXamlCompilation)' == ''">false</_AvaloniaSkipXamlCompilation>
   </PropertyGroup>
 
@@ -71,7 +70,6 @@
       Output="$(AvaloniaResourcesTemporaryFilePath)"
       Root="$(MSBuildProjectDirectory)"
       Resources="@(AvaloniaResource)"
-      EmbeddedResources="@(EmbeddedResources)"
       ReportImportance="$(AvaloniaXamlReportImportance)"/>
     <Exec 
       Condition="'$(_AvaloniaUseExternalMSBuild)' == 'true'"
@@ -106,7 +104,6 @@
       AssemblyOriginatorKeyFile="$(AssemblyOriginatorKeyFile)"
       SignAssembly="$(SignAssembly)"
       DelaySign="$(DelaySign)"
-      EnableComInteropPatching="$(_AvaloniaPatchComInterop)"
       SkipXamlCompilation="$(_AvaloniaSkipXamlCompilation)"
       DebuggerLaunch="$(AvaloniaXamlIlDebuggerLaunch)"
     />

+ 1 - 4
src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs

@@ -37,8 +37,7 @@ namespace Avalonia.Build.Tasks
             var res = XamlCompilerTaskExecutor.Compile(BuildEngine, input,
                 File.ReadAllLines(ReferencesFilePath).Where(l => !string.IsNullOrWhiteSpace(l)).ToArray(),
                 ProjectDirectory, OutputPath, VerifyIl, outputImportance,
-                (SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null,
-                EnableComInteropPatching, SkipXamlCompilation, DebuggerLaunch);
+                (SignAssembly && !DelaySign) ? AssemblyOriginatorKeyFile : null, SkipXamlCompilation, DebuggerLaunch);
             if (!res.Success)
                 return false;
             if (!res.WrittenFile)
@@ -72,8 +71,6 @@ namespace Avalonia.Build.Tasks
         public string OutputPath { get; set; }
 
         public bool VerifyIl { get; set; }
-        
-        public bool EnableComInteropPatching { get; set; }
         public bool SkipXamlCompilation { get; set; }
         
         public string AssemblyOriginatorKeyFile { get; set; }

+ 0 - 6
src/Avalonia.Build.Tasks/GenerateAvaloniaResourcesTask.cs

@@ -18,8 +18,6 @@ namespace Avalonia.Build.Tasks
         public string Root { get; set; }
         [Required]
         public string Output { get; set; }
-        [Required]
-        public ITaskItem[] EmbeddedResources { get; set; }
 
         public string ReportImportance { get; set; }
 
@@ -148,10 +146,6 @@ namespace Avalonia.Build.Tasks
             Enum.TryParse<MessageImportance>(ReportImportance, out _reportImportance);
 
             BuildEngine.LogMessage($"GenerateAvaloniaResourcesTask -> Root: {Root}, {Resources?.Count()} resources, Output:{Output}", _reportImportance < MessageImportance.Low ? MessageImportance.High : _reportImportance);
-
-            foreach (var r in EmbeddedResources.Where(r => r.ItemSpec.EndsWith(".xaml") || r.ItemSpec.EndsWith(".paml") || r.ItemSpec.EndsWith(".axaml")))
-                BuildEngine.LogWarning(BuildEngineErrorCode.LegacyResmScheme, r.ItemSpec,
-                    "XAML file is packed using legacy EmbeddedResource/resm scheme, relative URIs won't work");
             var resources = BuildResourceSources();
 
             if (!PreProcessXamlFiles(resources))

+ 1 - 2
src/Avalonia.Build.Tasks/Program.cs

@@ -44,8 +44,7 @@ namespace Avalonia.Build.Tasks
                 OutputPath = args[2],
                 BuildEngine = new ConsoleBuildEngine(),
                 ProjectDirectory = Directory.GetCurrentDirectory(),
-                VerifyIl = true,
-                EnableComInteropPatching = true
+                VerifyIl = true
             }.Execute() ?
                 0 :
                 2;

+ 0 - 32
src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.Helpers.cs

@@ -24,38 +24,6 @@ namespace Avalonia.Build.Tasks
             string Name { get; }
             IEnumerable<IResource> Resources { get; }
         }
-        
-        class EmbeddedResources : IResourceGroup
-        {
-            private readonly AssemblyDefinition _asm;
-            public string Name => "EmbeddedResource";
-
-            public IEnumerable<IResource> Resources => _asm.MainModule.Resources.OfType<EmbeddedResource>()
-                .Select(r => new WrappedResource(_asm, r)).ToList();
-
-            public EmbeddedResources(AssemblyDefinition asm)
-            {
-                _asm = asm;
-            }
-            class WrappedResource : IResource
-            {
-                private readonly AssemblyDefinition _asm;
-                private readonly EmbeddedResource _res;
-
-                public WrappedResource(AssemblyDefinition asm, EmbeddedResource res)
-                {
-                    _asm = asm;
-                    _res = res;
-                }
-
-                public string Uri => $"resm:{Name}?assembly={_asm.Name.Name}";
-                public string Name => _res.Name;
-                public string FilePath => Name;
-                public byte[] FileContents => _res.GetResourceData();
-
-                public void Remove() => _asm.MainModule.Resources.Remove(_res);
-            }
-        }
 
         class AvaloniaResources : IResourceGroup
         {

+ 5 - 12
src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs

@@ -39,15 +39,15 @@ namespace Avalonia.Build.Tasks
 
         public static CompileResult Compile(IBuildEngine engine, string input, string[] references,
             string projectDirectory,
-            string output, bool verifyIl, MessageImportance logImportance, string strongNameKey, bool patchCom,
+            string output, bool verifyIl, MessageImportance logImportance, string strongNameKey,
             bool skipXamlCompilation)
         {
-            return Compile(engine, input, references, projectDirectory, output, verifyIl, logImportance, strongNameKey, patchCom, skipXamlCompilation, debuggerLaunch:false);
+            return Compile(engine, input, references, projectDirectory, output, verifyIl, logImportance, strongNameKey, skipXamlCompilation, debuggerLaunch:false);
         }
 
         internal static CompileResult Compile(IBuildEngine engine, string input, string[] references,
             string projectDirectory,
-            string output, bool verifyIl, MessageImportance logImportance, string strongNameKey, bool patchCom, bool skipXamlCompilation, bool debuggerLaunch)
+            string output, bool verifyIl, MessageImportance logImportance, string strongNameKey, bool skipXamlCompilation, bool debuggerLaunch)
         {
             var typeSystem = new CecilTypeSystem(
                 references.Where(r => !r.ToLowerInvariant().EndsWith("avalonia.build.tasks.dll")),
@@ -58,15 +58,12 @@ namespace Avalonia.Build.Tasks
             if (!skipXamlCompilation)
             {
                 var compileRes = CompileCore(engine, typeSystem, projectDirectory, verifyIl, logImportance, debuggerLaunch);
-                if (compileRes == null && !patchCom)
+                if (compileRes == null)
                     return new CompileResult(true);
                 if (compileRes == false)
                     return new CompileResult(false);
             }
 
-            if (patchCom)
-                ComInteropHelper.PatchAssembly(asm, typeSystem);
-
             var writerParameters = new WriterParameters { WriteSymbols = asm.MainModule.HasSymbols };
             if (!string.IsNullOrWhiteSpace(strongNameKey))
                 writerParameters.StrongNameKeyBlob = File.ReadAllBytes(strongNameKey);
@@ -112,9 +109,8 @@ namespace Avalonia.Build.Tasks
                 }
             }
             var asm = typeSystem.TargetAssemblyDefinition;
-            var emres = new EmbeddedResources(asm);
             var avares = new AvaloniaResources(asm, projectDirectory);
-            if (avares.Resources.Count(CheckXamlName) == 0 && emres.Resources.Count(CheckXamlName) == 0)
+            if (avares.Resources.Count(CheckXamlName) == 0)
                 // Nothing to do
                 return null;
 
@@ -436,9 +432,6 @@ namespace Avalonia.Build.Tasks
                 return true;
             }
             
-            if (emres.Resources.Count(CheckXamlName) != 0)
-                if (!CompileGroup(emres))
-                    return false;
             if (avares.Resources.Count(CheckXamlName) != 0)
             {
                 if (!CompileGroup(avares))

+ 0 - 3
src/Avalonia.MicroCom/Avalonia.MicroCom.csproj

@@ -3,9 +3,6 @@
       <TargetFramework>netstandard2.0</TargetFramework>
       <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
   </PropertyGroup>
-  <PropertyGroup>
-    <_AvaloniaPatchComInterop>true</_AvaloniaPatchComInterop>
-  </PropertyGroup>
   <ItemGroup>
     <ProjectReference Include="..\Avalonia.Build.Tasks\Avalonia.Build.Tasks.csproj">
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>

+ 2 - 2
tests/Avalonia.DesignerSupport.TestApp/Avalonia.DesignerSupport.TestApp.csproj

@@ -8,9 +8,9 @@
     <Compile Update="**\*.xaml.cs">
       <DependentUpon>%(Filename)</DependentUpon>
     </Compile>
-    <EmbeddedResource Include="**\*.xaml">
+    <AvaloniaResource Include="**\*.xaml">
       <SubType>Designer</SubType>
-    </EmbeddedResource>
+    </AvaloniaResource>
   </ItemGroup>
 
   <ItemGroup>