Browse Source

Fix support for packages without strong name

pull/4985/head
Nikita Tsukanov 6 years ago
parent
commit
6b662026ef
  1. 2
      src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs
  2. 61
      tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs

2
src/Markup/Avalonia.Markup.Xaml.Loader/AvaloniaXamlIlRuntimeCompiler.cs

@ -142,7 +142,7 @@ namespace Avalonia.Markup.Xaml.XamlIl
if(string.IsNullOrWhiteSpace(name)) if(string.IsNullOrWhiteSpace(name))
return; return;
var key = assemblyName.GetPublicKey(); var key = assemblyName.GetPublicKey();
if (key != null) if (key != null && key.Length != 0)
name += ", PublicKey=" + BitConverter.ToString(key).Replace("-", "").ToUpperInvariant(); name += ", PublicKey=" + BitConverter.ToString(key).Replace("-", "").ToUpperInvariant();
_sreAsm.SetCustomAttribute(new CustomAttributeBuilder( _sreAsm.SetCustomAttribute(new CustomAttributeBuilder(
_ignoresAccessChecksFromAttribute.GetConstructors()[0], _ignoresAccessChecksFromAttribute.GetConstructors()[0],

61
tests/Avalonia.DesignerSupport.Tests/DesignerSupportTests.cs

@ -11,6 +11,7 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Remote.Protocol; using Avalonia.Remote.Protocol;
using Avalonia.Remote.Protocol.Designer; using Avalonia.Remote.Protocol.Designer;
using Avalonia.Remote.Protocol.Viewport;
using Xunit; using Xunit;
using Xunit.Extensions; using Xunit.Extensions;
@ -31,19 +32,38 @@ namespace Avalonia.DesignerSupport.Tests
@"..\..\..\..\..\tests/Avalonia.DesignerSupport.TestApp/bin/$BUILD/netcoreapp3.1/", @"..\..\..\..\..\tests/Avalonia.DesignerSupport.TestApp/bin/$BUILD/netcoreapp3.1/",
"Avalonia.DesignerSupport.TestApp", "Avalonia.DesignerSupport.TestApp",
"Avalonia.DesignerSupport.TestApp.dll", "Avalonia.DesignerSupport.TestApp.dll",
@"..\..\..\..\..\tests\Avalonia.DesignerSupport.TestApp\MainWindow.xaml"), @"..\..\..\..\..\tests\Avalonia.DesignerSupport.TestApp\MainWindow.xaml",
"win32"),
InlineData( InlineData(
@"..\..\..\..\..\samples\ControlCatalog.NetCore\bin\$BUILD\netcoreapp3.1\", @"..\..\..\..\..\samples\ControlCatalog.NetCore\bin\$BUILD\netcoreapp3.1\",
"ControlCatalog.NetCore", "ControlCatalog.NetCore",
"ControlCatalog.dll", "ControlCatalog.dll",
@"..\..\..\..\..\samples\ControlCatalog\MainWindow.xaml")] @"..\..\..\..\..\samples\ControlCatalog\MainWindow.xaml",
"win32"),
InlineData(
@"..\..\..\..\..\tests/Avalonia.DesignerSupport.TestApp/bin/$BUILD/netcoreapp3.1/",
"Avalonia.DesignerSupport.TestApp",
"Avalonia.DesignerSupport.TestApp.dll",
@"..\..\..\..\..\tests\Avalonia.DesignerSupport.TestApp\MainWindow.xaml",
"avalonia-remote"),
InlineData(
@"..\..\..\..\..\samples\ControlCatalog.NetCore\bin\$BUILD\netcoreapp3.1\",
"ControlCatalog.NetCore",
"ControlCatalog.dll",
@"..\..\..\..\..\samples\ControlCatalog\MainWindow.xaml",
"avalonia-remote")]
public async Task Designer_In_Win32_Mode_Should_Provide_Valid_Hwnd( public async Task Designer_In_Win32_Mode_Should_Provide_Valid_Hwnd(
string outputDir, string outputDir,
string executableName, string executableName,
string assemblyName, string assemblyName,
string xamlFile) string xamlFile,
string method)
{ {
Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)); outputDir = Path.GetFullPath(outputDir.Replace('\\', Path.DirectorySeparatorChar));
xamlFile = Path.GetFullPath(xamlFile.Replace('\\', Path.DirectorySeparatorChar));
if (method == "win32")
Skip.IfNot(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
var xaml = File.ReadAllText(xamlFile); var xaml = File.ReadAllText(xamlFile);
string buildType; string buildType;
@ -56,6 +76,8 @@ namespace Avalonia.DesignerSupport.Tests
var sessionId = Guid.NewGuid(); var sessionId = Guid.NewGuid();
long handle = 0; long handle = 0;
bool success = false;
string error = null;
var resultMessageReceivedToken = new CancellationTokenSource(); var resultMessageReceivedToken = new CancellationTokenSource();
@ -71,6 +93,18 @@ namespace Avalonia.DesignerSupport.Tests
if (msg is StartDesignerSessionMessage start) if (msg is StartDesignerSessionMessage start)
{ {
Assert.Equal(sessionId, Guid.Parse(start.SessionId)); Assert.Equal(sessionId, Guid.Parse(start.SessionId));
if (method == "avalonia-remote")
{
await conn.Send(new ClientSupportedPixelFormatsMessage
{
Formats = new[] { PixelFormat.Rgba8888 }
});
await conn.Send(new ClientViewportAllocatedMessage
{
DpiX = 96, DpiY = 96, Width = 1024, Height = 768
});
}
await conn.Send(new UpdateXamlMessage await conn.Send(new UpdateXamlMessage
{ {
AssemblyPath = Path.Combine(outputDir, assemblyName), AssemblyPath = Path.Combine(outputDir, assemblyName),
@ -80,8 +114,14 @@ namespace Avalonia.DesignerSupport.Tests
else if (msg is UpdateXamlResultMessage result) else if (msg is UpdateXamlResultMessage result)
{ {
if (result.Error != null) if (result.Error != null)
{
error = result.Error;
outputHelper.WriteLine(result.Error); outputHelper.WriteLine(result.Error);
handle = result.Handle != null ? long.Parse(result.Handle) : 0; }
else
success = true;
if (method == "win32")
handle = result.Handle != null ? long.Parse(result.Handle) : 0;
resultMessageReceivedToken.Cancel(); resultMessageReceivedToken.Cancel();
conn.Dispose(); conn.Dispose();
} }
@ -91,7 +131,7 @@ namespace Avalonia.DesignerSupport.Tests
var cmdline = var cmdline =
$"exec --runtimeconfig \"{outputDir}{executableName}.runtimeconfig.json\" --depsfile \"{outputDir}{executableName}.deps.json\" " $"exec --runtimeconfig \"{outputDir}{executableName}.runtimeconfig.json\" --depsfile \"{outputDir}{executableName}.deps.json\" "
+ $" \"{DesignerAppPath.Replace("$BUILD", buildType)}\" " + $" \"{DesignerAppPath.Replace("$BUILD", buildType)}\" "
+ $"--transport tcp-bson://127.0.0.1:{port}/ --session-id {sessionId} --method win32 \"{outputDir}{executableName}.dll\""; + $"--transport tcp-bson://127.0.0.1:{port}/ --session-id {sessionId} --method {method} \"{outputDir}{executableName}.dll\"";
using (var proc = new Process using (var proc = new Process
{ {
@ -128,10 +168,15 @@ namespace Avalonia.DesignerSupport.Tests
} }
proc.WaitForExit(); proc.WaitForExit();
var stdout = proc.StandardOutput.ReadToEnd();
var stderr = proc.StandardError.ReadToEnd();
Assert.True(cancelled, Assert.True(cancelled,
$"Message Not Received.\n" + proc.StandardOutput.ReadToEnd() + "\n" + $"Message Not Received.\n" + proc.StandardOutput.ReadToEnd() + "\n" +
proc.StandardError.ReadToEnd()); stderr + "\n" + stdout);
Assert.NotEqual(0, handle); Assert.True(success, error);
if (method == "win32")
Assert.NotEqual(0, handle);
} }
} }

Loading…
Cancel
Save