Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target netcore on editor and bootstrapper projects #1907

Merged
merged 30 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bba25c1
Target netcore on editor and bootstrapper projects
glopesdev Jul 12, 2024
8f6124f
Avoid relying on entry assembly for netcore
glopesdev Jul 12, 2024
5bee96f
Add project framework for netcore bootstrapper
glopesdev Jul 14, 2024
c5807c0
Restrict ScintillaNET update to .NET core app
glopesdev Jul 22, 2024
d942d16
Ensure WindowsDesktop runtime directory is scanned
glopesdev Jul 22, 2024
758e5fb
Avoid using netcore obsolete property
glopesdev Jul 22, 2024
a5d2c33
Avoid adding .NET framework dependent references
glopesdev Jul 22, 2024
261d1c0
Avoid configuring high DPI mode in App.manifest
glopesdev Jul 22, 2024
b22330d
Remove unused control scaling code for netcore
glopesdev Jul 23, 2024
118fe0d
Target post build event to avoid empty target dir
glopesdev Jul 23, 2024
5602546
Enable windows targeting for non-windows CI
glopesdev Jul 23, 2024
fd979ce
Repack bootstrapper only for net48 target
glopesdev Jul 23, 2024
9262091
Ensure argument name for argument null exceptions
glopesdev Jul 23, 2024
7d5391a
Remove netcore bootstrapper target from CI builds
glopesdev Jul 23, 2024
585d0ea
Add multi-targeting support to Bonsai.csproj
PathogenDavid Jul 31, 2024
b753600
Target net8.0 for core and design assemblies
glopesdev Jul 31, 2024
7b69ef5
Remove all uses of legacy serialization APIs
glopesdev Jul 31, 2024
7e1891b
Use TargetFrameworkIdentifier for item conditions
glopesdev Jul 31, 2024
c3a0a76
Target net8.0 for configuration and nuget projects
glopesdev Jul 31, 2024
4af1f33
Avoid using obsolete CodeBase property
glopesdev Jul 31, 2024
31c0f17
Update package dependencies
glopesdev Jul 31, 2024
a0a6009
Assume MSIL architecture when scanning extensions
glopesdev Jul 31, 2024
6d79f45
Avoid using AssemblyName processor architecture
glopesdev Aug 1, 2024
fe3f5fb
Remove unused control scaling code for net8.0
glopesdev Aug 1, 2024
52e24d8
Fix indentation
glopesdev Aug 1, 2024
d107c54
Change TargetDir to OutputPath
glopesdev Aug 1, 2024
d0da51d
Bump minor version
glopesdev Aug 1, 2024
3561852
Drop serialization constructors from net8.0 target
glopesdev Aug 1, 2024
a2b58c6
Move checkbox images to Resources.resx
glopesdev Aug 2, 2024
cfa4e62
Reduce label margin to avoid control clipping
glopesdev Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Bonsai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ jobs:
# This happens before pack since the bootstrapper package uses it
- name: Repack bootstrapper
if: matrix.create-installer || env.UseRepackForBootstrapperPackage == 'true'
run: dotnet build Bonsai --no-restore --configuration ${{matrix.configuration}} -t:Repack
run: dotnet build Bonsai --no-restore --configuration ${{matrix.configuration}} -t:Repack -p:TargetFramework=net48

# ----------------------------------------------------------------------- Pack
# Since packages are core to Bonsai functionality we always pack them even if they won't be collected
Expand Down
5 changes: 4 additions & 1 deletion Bonsai.Configuration/Bonsai.Configuration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
<PropertyGroup>
<IsPackable>false</IsPackable>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<TargetFrameworks>net472;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net472;net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Bonsai.NuGet\Bonsai.NuGet.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
<PackageReference Include="System.CodeDom" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
11 changes: 9 additions & 2 deletions Bonsai.Configuration/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,18 @@ public static void RegisterPath(this PackageConfiguration configuration, string
catch (BadImageFormatException) { continue; }
catch (IOException) { continue; }

var locationKey = (assemblyName.Name, assemblyName.ProcessorArchitecture);
#if NET7_0_OR_GREATER
// Support for ProcessorArchitecture was removed in NET7 so assume MSIL for now
var processorArchitecture = ProcessorArchitecture.MSIL;
#else
var processorArchitecture = assemblyName.ProcessorArchitecture;
#endif

var locationKey = (assemblyName.Name, processorArchitecture);
if (!configuration.AssemblyLocations.Contains(locationKey))
{
configuration.AssemblyReferences.Add(assemblyName.Name);
configuration.AssemblyLocations.Add(assemblyName.Name, assemblyName.ProcessorArchitecture, assemblyFile);
configuration.AssemblyLocations.Add(assemblyName.Name, processorArchitecture, assemblyFile);
}
}
}
Expand Down
79 changes: 55 additions & 24 deletions Bonsai.Configuration/PackageConfigurationUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static bool IsTaggedPackage(PackageReaderBase package)
return tags != null && tags.Contains(PackageTagFilter);
}

static string ResolvePlatformNameAlias(string name)
static ProcessorArchitecture ResolveArchitectureAlias(string name)
{
switch (name)
{
Expand All @@ -108,20 +108,20 @@ static string ResolvePlatformNameAlias(string name)
case "intel64":
case "x86-64":
case "x86_64":
return "x64";
return ProcessorArchitecture.Amd64;
case "win32":
case "x86":
case "ia32":
case "386":
return "x86";
return ProcessorArchitecture.X86;
default:
return string.Empty;
return ProcessorArchitecture.None;
}
}

static string ResolvePathPlatformName(string path)
static ProcessorArchitecture ResolvePathArchitecture(string path)
{
var platformName = string.Empty;
var architecture = ProcessorArchitecture.None;
var components = path.Split(DirectorySeparators, StringSplitOptions.RemoveEmptyEntries);
components = Array.ConvertAll(components, name => name.ToLower());

Expand All @@ -130,23 +130,24 @@ static string ResolvePathPlatformName(string path)
{
for (int i = 3; i < components.Length; i++)
{
platformName = ResolvePlatformNameAlias(components[i]);
if (!string.IsNullOrEmpty(platformName)) break;
architecture = ResolveArchitectureAlias(components[i]);
if (architecture != ProcessorArchitecture.None) break;
}
}

return platformName;
return architecture;
}

static IEnumerable<string> GetAssemblyLocations(NuGetFramework projectFramework, PackageReaderBase package)
static IEnumerable<IGrouping<ProcessorArchitecture, string>> GetArchitectureSpecificAssemblyLocations(NuGetFramework projectFramework, PackageReaderBase package)
{
var nearestFramework = package.GetItems(PackagingConstants.Folders.Build).GetNearest(projectFramework);
if (nearestFramework == null) return Enumerable.Empty<string>();
if (nearestFramework == null) return Enumerable.Empty<IGrouping<ProcessorArchitecture, string>>();

return from file in nearestFramework.Items
where Path.GetExtension(file) == AssemblyExtension &&
!string.IsNullOrEmpty(ResolvePathPlatformName(file))
select PathUtility.GetPathWithForwardSlashes(file);
where Path.GetExtension(file) == AssemblyExtension
let architecture = ResolvePathArchitecture(file)
where architecture != ProcessorArchitecture.None
group PathUtility.GetPathWithForwardSlashes(file) by architecture;
}

static IEnumerable<LibraryFolder> GetLibraryFolders(PackageReaderBase package, string installPath)
Expand All @@ -164,9 +165,11 @@ static IEnumerable<LibraryFolder> GetBuildLibraryFolders(PackageReaderBase packa

return from file in nativeFramework.Items
group file by Path.GetDirectoryName(file) into folder
let platform = ResolvePathPlatformName(folder.Key)
where !string.IsNullOrWhiteSpace(platform)
select new LibraryFolder(CombinePath(installPath, folder.Key), platform);
let architecture = ResolvePathArchitecture(folder.Key)
where architecture != ProcessorArchitecture.None
select new LibraryFolder(
CombinePath(installPath, folder.Key),
architecture == ProcessorArchitecture.X86 ? "x86" : "x64");
}

static IEnumerable<LibraryFolder> GetRuntimeLibraryFolders(PackageReaderBase package, string installPath)
Expand All @@ -189,21 +192,39 @@ static IEnumerable<string> GetCompatibleAssemblyReferences(NuGetFramework projec

void RegisterAssemblyLocations(PackageReaderBase package, string installPath, string relativePath, bool addReferences)
{
var assemblyLocations = GetAssemblyLocations(bootstrapperFramework, package);
RegisterAssemblyLocations(assemblyLocations, installPath, relativePath, addReferences);
var platformSpecificLocations = GetArchitectureSpecificAssemblyLocations(bootstrapperFramework, package);
foreach (var assemblyLocations in platformSpecificLocations)
{
RegisterAssemblyLocations(assemblyLocations, installPath, relativePath, addReferences, assemblyLocations.Key);
}
}

void RegisterAssemblyLocations(IEnumerable<string> assemblyLocations, string installPath, string relativePath, bool addReferences)
void RegisterAssemblyLocations(
IEnumerable<string> assemblyLocations,
string installPath,
string relativePath,
bool addReferences,
ProcessorArchitecture processorArchitecture = ProcessorArchitecture.None)
{
foreach (var path in assemblyLocations)
{
var assemblyFile = CombinePath(installPath, path);
var assemblyName = AssemblyName.GetAssemblyName(assemblyFile);
if (processorArchitecture == ProcessorArchitecture.None)
{
#if NET7_0_OR_GREATER
// Support for ProcessorArchitecture was removed in NET7 so assume MSIL for now
processorArchitecture = ProcessorArchitecture.MSIL;
#else
processorArchitecture = assemblyName.ProcessorArchitecture;
#endif
}

var assemblyLocation = CombinePath(relativePath, path);
var assemblyLocationKey = (assemblyName.Name, assemblyName.ProcessorArchitecture);
var assemblyLocationKey = (assemblyName.Name, processorArchitecture);
if (!packageConfiguration.AssemblyLocations.Contains(assemblyLocationKey))
{
packageConfiguration.AssemblyLocations.Add(assemblyName.Name, assemblyName.ProcessorArchitecture, assemblyLocation);
packageConfiguration.AssemblyLocations.Add(assemblyName.Name, processorArchitecture, assemblyLocation);
}
else if (packageConfiguration.AssemblyLocations[assemblyLocationKey].Location != assemblyLocation)
{
Expand All @@ -219,8 +240,11 @@ void RegisterAssemblyLocations(IEnumerable<string> assemblyLocations, string ins

void RemoveAssemblyLocations(PackageReaderBase package, string installPath, bool removeReference)
{
var assemblyLocations = GetAssemblyLocations(bootstrapperFramework, package);
RemoveAssemblyLocations(assemblyLocations, installPath, removeReference);
var platformSpecificLocations = GetArchitectureSpecificAssemblyLocations(bootstrapperFramework, package);
foreach (var assemblyLocations in platformSpecificLocations)
{
RemoveAssemblyLocations(assemblyLocations, installPath, removeReference);
}
}

void RemoveAssemblyLocations(IEnumerable<string> assemblyLocations, string installPath, bool removeReference)
Expand Down Expand Up @@ -462,6 +486,13 @@ public override Task OnPackageInstalledAsync(PackageIdentity package, NuGetFrame
}
}

// Reference assemblies should generally always be MSIL but for backwards compatibility
// we allow the processor architecture to be set by the assembly for .NET Framework.
// In future releases of the modern .NET bootstrapper we need to revisit this entirely
// and ensure that none of these considerations impact on the Bonsai.config file,
// most likely by removing all platform-specific paths and references. Runtime assembly
// resolution is OS-specific and architecture-specific and should not be versioned together
// with the package dependency graph.
var assemblyLocations = GetCompatibleAssemblyReferences(projectFramework, packageReader);
Owner.RegisterAssemblyLocations(assemblyLocations, installPath, relativePath, taggedPackage);
packageConfiguration.Save();
Expand Down
7 changes: 3 additions & 4 deletions Bonsai.Configuration/ScriptExtensionsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if NET472_OR_GREATER
using Microsoft.CSharp;
using Microsoft.CSharp;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Frameworks;
Expand Down Expand Up @@ -181,13 +180,13 @@ string GetAssemblyLocation(string fileName)
else
{
var assemblyName = AssemblyName.GetAssemblyName(assemblyFile);
var assemblyUri = new Uri(assemblyFile).AbsoluteUri;
configuration.AssemblyReferences.Add(assemblyName.Name);
configuration.AssemblyLocations.Add(assemblyName.Name, ProcessorArchitecture.MSIL, assemblyName.CodeBase);
configuration.AssemblyLocations.Add(assemblyName.Name, ProcessorArchitecture.MSIL, assemblyUri);
scriptEnvironment.AssemblyName = assemblyName;
}
return scriptEnvironment;
}
}
}
}
#endif
8 changes: 4 additions & 4 deletions Bonsai.Core.Tests/Bonsai.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<EmbeddedResource Include="**\*.bonsai" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.5.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.5.0" />
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
12 changes: 6 additions & 6 deletions Bonsai.Core/Bonsai.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
<Title>Bonsai - Core Library</Title>
<Description>Bonsai Core Library containing base classes and workflow infrastructure.</Description>
<PackageTags>Bonsai Rx Reactive Extensions</PackageTags>
<TargetFrameworks>net472;netstandard2.0;net6.0</TargetFrameworks>
<TargetFrameworks>net472;netstandard2.0;net8.0</TargetFrameworks>
<RootNamespace>Bonsai</RootNamespace>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net472'">
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="Rx-Linq" Version="2.2.5" />
<PackageReference Include="Rx-PlatformServices" Version="2.2.5" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Reactive" Version="6.0.0" />
<PackageReference Include="System.CodeDom" Version="6.0.0" />
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="System.CodeDom" Version="8.0.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETStandard'">
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1106,7 +1106,7 @@ static ExpressionBuilder UnwrapConvert(ExpressionBuilder builder, Func<Expressio
{
if (builder == null)
{
throw new ArgumentNullException("builder");
throw new ArgumentNullException(nameof(builder));
}

if (builder is InspectBuilder inspectBuilder)
Expand Down
2 changes: 2 additions & 0 deletions Bonsai.Core/WorkflowBuildException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public WorkflowBuildException(string message, ExpressionBuilder builder, Excepti
{
}

#if NETFRAMEWORK
/// <summary>
/// Initializes a new instance of the <see cref="WorkflowBuildException"/> class with
/// serialized data.
Expand All @@ -92,5 +93,6 @@ protected WorkflowBuildException(SerializationInfo info, StreamingContext contex
: base(info, context)
{
}
#endif
}
}
2 changes: 2 additions & 0 deletions Bonsai.Core/WorkflowException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public WorkflowException(string message, ExpressionBuilder builder, Exception in
Builder = builder;
}

#if NETFRAMEWORK
/// <summary>
/// Initializes a new instance of the <see cref="WorkflowException"/> class with
/// serialized data.
Expand All @@ -94,6 +95,7 @@ protected WorkflowException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
#endif

/// <summary>
/// Gets the <see cref="ExpressionBuilder"/> instance that was the cause for the exception.
Expand Down
2 changes: 2 additions & 0 deletions Bonsai.Core/WorkflowRuntimeException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public WorkflowRuntimeException(string message, ExpressionBuilder builder, Excep
{
}

#if NETFRAMEWORK
/// <summary>
/// Initializes a new instance of the <see cref="WorkflowRuntimeException"/> class with
/// serialized data.
Expand All @@ -92,5 +93,6 @@ protected WorkflowRuntimeException(SerializationInfo info, StreamingContext cont
: base(info, context)
{
}
#endif
}
}
16 changes: 10 additions & 6 deletions Bonsai.Design/Bonsai.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
<Title>Bonsai - Design Library</Title>
<Description>Bonsai Design Library containing base visualizer classes and editor infrastructure.</Description>
<PackageTags>Bonsai Design Rx Reactive Extensions</PackageTags>
<TargetFrameworks>net472;net8.0-windows</TargetFrameworks>
<UseWindowsForms>true</UseWindowsForms>
<TargetFramework>net472</TargetFramework>
</PropertyGroup>
<ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
<PackageReference Include="jacobslusser.ScintillaNET" Version="3.6.3" />
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
<Reference Include="System.Design" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<PackageReference Include="fernandreu.ScintillaNET" Version="4.2.0" />
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Bonsai.Core\Bonsai.Core.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Design" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Bonsai.Design/MemberSelectorEditorController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ internal void InitializeMemberTree(TreeNodeCollection nodes, Type componentType)
{
if (componentType == null)
{
throw new ArgumentNullException("componentType");
throw new ArgumentNullException(nameof(componentType));
}

componentType.VisitMember((member, memberType) => EnsureNode(nodes, member.Name, memberType));
Expand Down
4 changes: 3 additions & 1 deletion Bonsai.Design/PropertyGrid.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Drawing;
using System.Diagnostics;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;

Expand All @@ -16,6 +17,7 @@ protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
base.ScaleControl(factor, specified);
}

[Conditional("NETFRAMEWORK")]
internal static void ScaleDescriptionPanel(System.Windows.Forms.PropertyGrid propertyGrid, SizeF factor)
{
foreach (Control control in propertyGrid.Controls)
Expand Down
2 changes: 1 addition & 1 deletion Bonsai.Design/TypeVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static void VisitMember(this Type type, Action<MemberInfo, Type> visito
{
if (type == null)
{
throw new ArgumentNullException("componentType");
throw new ArgumentNullException(nameof(type));
}

foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.Public)
Expand Down
Loading