diff --git a/source/Directory.Build.props b/source/Directory.Build.props
index 3461e7ae7..83b3d91a7 100644
--- a/source/Directory.Build.props
+++ b/source/Directory.Build.props
@@ -8,7 +8,6 @@
embedded
true
true
- true
diff --git a/source/Nuke.Common/Nuke.Common.props b/source/Nuke.Common/Nuke.Common.props
index 9827b4735..744f4e105 100644
--- a/source/Nuke.Common/Nuke.Common.props
+++ b/source/Nuke.Common/Nuke.Common.props
@@ -5,7 +5,6 @@
false
$(MSBuildWarningsAsErrors);CS8785
$(NoWarn);SYSLIB0050;SYSLIB0051
- true
diff --git a/source/Nuke.Tooling.Tests/NewInstanceTest.cs b/source/Nuke.Tooling.Tests/NewInstanceTest.cs
new file mode 100644
index 000000000..def17bec9
--- /dev/null
+++ b/source/Nuke.Tooling.Tests/NewInstanceTest.cs
@@ -0,0 +1,31 @@
+// Copyright 2023 Maintainers of NUKE.
+// Distributed under the MIT License.
+// https://github.com/nuke-build/nuke/blob/master/LICENSE
+
+using FluentAssertions;
+using Nuke.Common.Tooling;
+using System;
+using Xunit;
+
+namespace Nuke.Common.Tests;
+
+public class NewInstanceTest
+{
+ [Serializable]
+ public class SimpleEntity : ISettingsEntity
+ {
+ public int Integer { get; set; }
+ public string String { get; set; }
+ }
+
+ [Fact]
+ public void TestSimpleEntity()
+ {
+ var entity = new SimpleEntity { Integer = 1, String = "test" };
+ var newInstance = entity.NewInstance();
+
+ newInstance.Integer.Should().Be(entity.Integer);
+ newInstance.String.Should().Be(entity.String);
+ }
+
+}
diff --git a/source/Nuke.Tooling.Tests/Nuke.Tooling.Tests.csproj b/source/Nuke.Tooling.Tests/Nuke.Tooling.Tests.csproj
index d2222e881..2267c07f2 100644
--- a/source/Nuke.Tooling.Tests/Nuke.Tooling.Tests.csproj
+++ b/source/Nuke.Tooling.Tests/Nuke.Tooling.Tests.csproj
@@ -1,7 +1,7 @@
-
+
- net6.0
+ net8.0
diff --git a/source/Nuke.Tooling/SettingsEntity.NewInstance.cs b/source/Nuke.Tooling/SettingsEntity.NewInstance.cs
index 9b129fea6..54c7e05d5 100644
--- a/source/Nuke.Tooling/SettingsEntity.NewInstance.cs
+++ b/source/Nuke.Tooling/SettingsEntity.NewInstance.cs
@@ -1,4 +1,4 @@
-// Copyright 2023 Maintainers of NUKE.
+// Copyright 2024 Maintainers of NUKE.
// Distributed under the MIT License.
// https://github.com/nuke-build/nuke/blob/master/LICENSE
@@ -7,6 +7,7 @@
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using JetBrains.Annotations;
+
#pragma warning disable SYSLIB0011
namespace Nuke.Common.Tooling;
@@ -17,18 +18,20 @@ public static partial class SettingsEntityExtensions
public static T NewInstance(this T settingsEntity)
where T : ISettingsEntity
{
+ AppContext.SetSwitch("System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization", isEnabled: true);
+
var binaryFormatter = new BinaryFormatter();
using var memoryStream = new MemoryStream();
binaryFormatter.Serialize(memoryStream, settingsEntity);
memoryStream.Seek(offset: 0, loc: SeekOrigin.Begin);
- var newInstance = (T) binaryFormatter.Deserialize(memoryStream);
+ var newInstance = (T)binaryFormatter.Deserialize(memoryStream);
if (newInstance is ToolSettings toolSettings)
{
- toolSettings.ProcessArgumentConfigurator = ((ToolSettings) (object) settingsEntity).ProcessArgumentConfigurator;
- toolSettings.ProcessLogger = ((ToolSettings) (object) settingsEntity).ProcessLogger;
- toolSettings.ProcessExitHandler = ((ToolSettings) (object) settingsEntity).ProcessExitHandler;
+ toolSettings.ProcessArgumentConfigurator = ((ToolSettings)(object)settingsEntity).ProcessArgumentConfigurator;
+ toolSettings.ProcessLogger = ((ToolSettings)(object)settingsEntity).ProcessLogger;
+ toolSettings.ProcessExitHandler = ((ToolSettings)(object)settingsEntity).ProcessExitHandler;
}
return newInstance;