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

AppDomain configuration is serialized without using BinFmt #9320

Merged
merged 25 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2f93aea
AppDomain configuration is serialized without using BinFmt
MichalPavlik Oct 11, 2023
c4f8cf1
Added new unit tests. Fixed 'null' bug.
MichalPavlik Oct 17, 2023
3ee6aef
Fix CG alerts caused by RoslynTools.MSBuild 17.7.2 (#9310)
GangWang01 Oct 9, 2023
87b844b
Fix policheck error (#9311)
JaynieBai Oct 10, 2023
64dfc0c
Mention unification in RAR found-conflicts message (#9226)
rainersigwald Oct 10, 2023
7098c57
Correct success for /preprocess /targets builds (#8908)
Forgind Oct 10, 2023
e4cb483
Enable Windows Disabled Drive Enumeration Tests (#9266)
JaynieBai Oct 10, 2023
f79b38f
Packages sourcing doc (#8475)
JanKrivanek Oct 10, 2023
4aec098
Catch the illegal argument exception in Net Framework! (#8839)
JaynieBai Oct 10, 2023
d374923
Remove stale .vsconfig components (#8862)
rainersigwald Oct 10, 2023
9de0dd8
Update dependencies from https://github.com/dotnet/roslyn build 20231…
dotnet-maestro[bot] Oct 11, 2023
56cb905
Re-enable IdenticalSubmissionsShouldCompleteAndNotHangTheBuildOnMissi…
ladipro Oct 11, 2023
48b97b2
Delete ExcludeFromStyleCop (#9247)
ladipro Oct 11, 2023
cb02c2c
Make repo buildable with VS 17.8.0 Preview 3.0 (#9319)
ladipro Oct 12, 2023
98ac0d8
Add a job for experimental Framework MSBuild insertion to a pipeline …
AR-May Oct 12, 2023
f471b78
Localized file check-in by OneLocBuild Task: Build definition ID 9434…
dotnet-bot Oct 13, 2023
8f7335f
Update dependencies from https://github.com/dotnet/roslyn build 20231…
dotnet-maestro[bot] Oct 17, 2023
619dca4
Cleanup: Delete NGen of T (#9263)
ladipro Oct 17, 2023
96dd579
Merge branch 'main' of https://github.com/dotnet/msbuild
MichalPavlik Oct 17, 2023
0348063
Added change wave with checks
MichalPavlik Oct 17, 2023
3e69ceb
Type member changed to local variable
MichalPavlik Oct 17, 2023
30f830f
Update src/Build/BackEnd/Node/NodeConfiguration.cs
MichalPavlik Oct 18, 2023
0df3f80
Update src/Shared/TaskHostConfiguration.cs
MichalPavlik Oct 18, 2023
2f6635e
Renamed local variable
MichalPavlik Oct 18, 2023
1d689c8
Added record to change waves docs
MichalPavlik Oct 18, 2023
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
3 changes: 3 additions & 0 deletions documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t

## Current Rotation of Change Waves

### 17.10
- [AppDomain configuration is serialized without using BinFmt](https://github.com/dotnet/msbuild/pull/9320) - feature can be opted out only if [BinaryFormatter](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) is allowed at runtime by editing `MSBuild.runtimeconfig.json`

### 17.8
- [[RAR] Don't do I/O on SDK-provided references](https://github.com/dotnet/msbuild/pull/8688)
- [Delete destination file before copy](https://github.com/dotnet/msbuild/pull/8685)
Expand Down
59 changes: 59 additions & 0 deletions src/Build.UnitTests/BackEnd/NodeConfiguration_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.BackEnd;
using Microsoft.Build.Execution;
using Microsoft.Build.Logging;
using Microsoft.Build.UnitTests.BackEnd;
using Shouldly;
using Xunit;

namespace Microsoft.Build.Engine.UnitTests.BackEnd
{
public class NodeConfiguration_Tests
{
#if FEATURE_APPDOMAIN
/// <summary>
/// Test serialization / deserialization of the AppDomainSetup instance.
/// </summary>
[Theory]
[InlineData(new byte[] { 1, 2, 3 })]
[InlineData(null)]
public void TestTranslationWithAppDomainSetup(byte[] configBytes)
{
AppDomainSetup setup = new AppDomainSetup();

NodeConfiguration config = new NodeConfiguration(
nodeId: 1,
buildParameters: new BuildParameters(),
forwardingLoggers: Array.Empty<LoggerDescription>(),
appDomainSetup: setup,
loggingNodeConfiguration: new LoggingNodeConfiguration());

setup.SetConfigurationBytes(configBytes);

((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
INodePacket packet = NodeConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

packet.ShouldBeOfType<NodeConfiguration>();
NodeConfiguration deserializedConfig = (NodeConfiguration)packet;

deserializedConfig.AppDomainSetup.ShouldNotBeNull();

if (configBytes is null)
{
deserializedConfig.AppDomainSetup.GetConfigurationBytes().ShouldBeNull();
}
else
{
deserializedConfig.AppDomainSetup.GetConfigurationBytes().SequenceEqual(configBytes).ShouldBeTrue();
}
}
#endif
}
}
52 changes: 52 additions & 0 deletions src/Build.UnitTests/BackEnd/TaskHostConfiguration_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;


Expand Down Expand Up @@ -376,6 +377,57 @@ public void TestTranslationWithNullDictionary()
Assert.Equal(expectedGlobalProperties, deserializedConfig.GlobalProperties);
}

#if FEATURE_APPDOMAIN
/// <summary>
/// Test serialization / deserialization of the AppDomainSetup instance.
/// </summary>
[Theory]
[InlineData(new byte[] { 1, 2, 3 })]
[InlineData(null)]
public void TestTranslationWithAppDomainSetup(byte[] configBytes)
{
AppDomainSetup setup = new AppDomainSetup();

TaskHostConfiguration config = new TaskHostConfiguration(
nodeId: 1,
startupDirectory: Directory.GetCurrentDirectory(),
buildProcessEnvironment: null,
culture: Thread.CurrentThread.CurrentCulture,
uiCulture: Thread.CurrentThread.CurrentUICulture,
appDomainSetup: setup,
lineNumberOfTask: 1,
columnNumberOfTask: 1,
projectFileOfTask: @"c:\my project\myproj.proj",
continueOnError: _continueOnErrorDefault,
taskName: "TaskName",
taskLocation: @"c:\MyTasks\MyTask.dll",
isTaskInputLoggingEnabled: false,
taskParameters: new Dictionary<string, object>(),
globalParameters: new Dictionary<string, string>(),
warningsAsErrors: null,
warningsNotAsErrors: null,
warningsAsMessages: null);

setup.SetConfigurationBytes(configBytes);

((ITranslatable)config).Translate(TranslationHelpers.GetWriteTranslator());
INodePacket packet = TaskHostConfiguration.FactoryForDeserialization(TranslationHelpers.GetReadTranslator());

TaskHostConfiguration deserializedConfig = packet as TaskHostConfiguration;

deserializedConfig.AppDomainSetup.ShouldNotBeNull();

if (configBytes is null)
{
deserializedConfig.AppDomainSetup.GetConfigurationBytes().ShouldBeNull();
}
else
{
deserializedConfig.AppDomainSetup.GetConfigurationBytes().SequenceEqual(configBytes).ShouldBeTrue();
}
}
#endif

/// <summary>
/// Test serialization / deserialization when the parameter dictionary is empty.
/// </summary>
Expand Down
25 changes: 24 additions & 1 deletion src/Build/BackEnd/Node/NodeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Diagnostics;

using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Logging;
#nullable disable

Expand Down Expand Up @@ -161,7 +162,28 @@ public void Translate(ITranslator translator)
translator.Translate(ref _buildParameters, BuildParameters.FactoryForDeserialization);
translator.TranslateArray(ref _forwardingLoggers, LoggerDescription.FactoryForTranslation);
#if FEATURE_APPDOMAIN
translator.TranslateDotNet(ref _appDomainSetup);
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10) || !Traits.Instance.EscapeHatches.IsBinaryFormatterSerializationAllowed)
{
byte[] appDomainConfigBytes = null;

// Set the configuration bytes just before serialization in case the SetConfigurationBytes was invoked during lifetime of this instance.
if (translator.Mode == TranslationDirection.WriteToStream)
{
appDomainConfigBytes = _appDomainSetup?.GetConfigurationBytes();
}

translator.Translate(ref appDomainConfigBytes);

if (translator.Mode == TranslationDirection.ReadFromStream)
{
_appDomainSetup = new AppDomainSetup();
_appDomainSetup.SetConfigurationBytes(appDomainConfigBytes);
}
}
else
{
translator.TranslateDotNet(ref _appDomainSetup);
}
#endif
translator.Translate(ref _loggingNodeConfiguration);
}
Expand All @@ -173,6 +195,7 @@ internal static INodePacket FactoryForDeserialization(ITranslator translator)
{
NodeConfiguration configuration = new NodeConfiguration();
configuration.Translate(translator);

return configuration;
}
#endregion
Expand Down
3 changes: 2 additions & 1 deletion src/Framework/ChangeWaves.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ internal class ChangeWaves
internal static readonly Version Wave17_4 = new Version(17, 4);
internal static readonly Version Wave17_6 = new Version(17, 6);
internal static readonly Version Wave17_8 = new Version(17, 8);
internal static readonly Version[] AllWaves = { Wave17_4, Wave17_6, Wave17_8 };
internal static readonly Version Wave17_10 = new Version(17, 10);
internal static readonly Version[] AllWaves = { Wave17_4, Wave17_6, Wave17_8, Wave17_10 };

/// <summary>
/// Special value indicating that all features behind all Change Waves should be enabled.
Expand Down
26 changes: 24 additions & 2 deletions src/Shared/TaskHostConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

using Microsoft.Build.Framework;
using Microsoft.Build.Shared;

#nullable disable
Expand Down Expand Up @@ -417,7 +417,28 @@ public void Translate(ITranslator translator)
translator.TranslateCulture(ref _culture);
translator.TranslateCulture(ref _uiCulture);
#if FEATURE_APPDOMAIN
translator.TranslateDotNet(ref _appDomainSetup);
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_10) || !Traits.Instance.EscapeHatches.IsBinaryFormatterSerializationAllowed)
MichalPavlik marked this conversation as resolved.
Show resolved Hide resolved
{
byte[] appDomainConfigBytes = null;

// Set the configuration bytes just before serialization in case the SetConfigurationBytes was invoked during lifetime of this instance.
if (translator.Mode == TranslationDirection.WriteToStream)
{
appDomainConfigBytes = _appDomainSetup?.GetConfigurationBytes();
}

translator.Translate(ref appDomainConfigBytes);

if (translator.Mode == TranslationDirection.ReadFromStream)
{
_appDomainSetup = new AppDomainSetup();
_appDomainSetup.SetConfigurationBytes(appDomainConfigBytes);
}
}
else
{
translator.TranslateDotNet(ref _appDomainSetup);
}
#endif
translator.Translate(ref _lineNumberOfTask);
translator.Translate(ref _columnNumberOfTask);
Expand Down Expand Up @@ -458,6 +479,7 @@ internal static INodePacket FactoryForDeserialization(ITranslator translator)
{
TaskHostConfiguration configuration = new TaskHostConfiguration();
configuration.Translate(translator);

return configuration;
}
}
Expand Down