-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Resolve net task host params from the project properties #11543
base: main
Are you sure you want to change the base?
Resolve net task host params from the project properties #11543
Conversation
msbuildArchitecture = msbuildArchitecture == String.Empty ? XMakeAttributes.MSBuildArchitectureValues.any : msbuildArchitecture.Trim(); | ||
msbuildRuntime = msbuildRuntime == String.Empty ? XMakeAttributes.MSBuildRuntimeValues.any : msbuildRuntime.Trim(); | ||
|
||
taskIdentityParameters.Add(XMakeAttributes.runtime, msbuildRuntime); | ||
taskIdentityParameters.Add(XMakeAttributes.architecture, msbuildArchitecture); | ||
} | ||
|
||
string hostPath = lookup.GetProperty("DOTNET_EXPERIMENTAL_HOST_PATH")?.EvaluatedValue; | ||
string msBuildAssemblyPath = Path.GetDirectoryName(lookup.GetProperty("RuntimeIdentifierGraphPath")?.EvaluatedValue) ?? string.Empty; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we should be able to find a better property - using the RID graph as a side effect may be prone to breakage or re-arrangement in the SDK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a workaround. we plan to add a separate property later
…ttps://github.com/YuliiaKovalova/msbuild into dev/ykovalova/use_project_props_for_sdk_resolution
/// <summary> | ||
/// Task host runtime. | ||
/// </summary> | ||
private string _runtime; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private string _runtime; | |
private readonly string _runtime; |
|
||
// Set the configuration bytes just before serialization in case the SetConfigurationBytes was invoked during lifetime of this instance. | ||
if (translator.Mode == TranslationDirection.WriteToStream) | ||
// Skip AppDomain configuration when targeting .NET Task Host (Runtime="Net"). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a list of all the runtime names and their meaning?
@@ -115,6 +116,8 @@ internal abstract class NodeEndpointOutOfProcBase : INodeEndpoint | |||
/// </summary> | |||
private BinaryWriter _binaryWriter; | |||
|
|||
private readonly IList<string> _versionHandshakeGroup = ["fileVersionMajor", "fileVersionMinor", "fileVersionBuild", "fileVersionPrivate"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private readonly IList<string> _versionHandshakeGroup = ["fileVersionMajor", "fileVersionMinor", "fileVersionBuild", "fileVersionPrivate"]; | |
private readonly ImmutableArray<string> _versionHandshakeGroup = ["fileVersionMajor", "fileVersionMinor", "fileVersionBuild", "fileVersionPrivate"]; |
Given this collection doesn't change consider a non-mutating type to make future mutations an explicit decision.
break; | ||
// NET Task host allows to connect to MSBuild.dll with the different handshake version. | ||
// We agreed to hardcode a value of 99 to bypass the protection for this scenario. | ||
if (_versionHandshakeGroup.Contains(handshakeComponents[i].Key) && handshakeComponents[i].Value == Handshake.NetTaskHostHandshakeVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the runtime host name treated as ordinal ignore case but the version handshake groups are ordinal?
public static byte CreateExtendedHeaderType(NodePacketType type) => (byte)((byte)type | ExtendedHeaderFlag); | ||
|
||
// Read extended header (returns version) | ||
public static byte ReadVersion(Stream stream) => (byte)stream.ReadByte(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL: that ReadByte
returns int
not byte
.
/// </summary> | ||
Arm64 = 128, | ||
} | ||
|
||
internal class Handshake | ||
{ | ||
public static int NetTaskHostHandshakeVersion = 99; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static int NetTaskHostHandshakeVersion = 99; | |
public const int NetTaskHostHandshakeVersion = 99; |
Or possible static readonly
// for NET the executable is resolved from DOTNET_EXPERIMENTAL_HOST_PATH | ||
s_msbuildName = IsHandshakeOptionEnabled(HandshakeOptions.NET) | ||
? string.Empty | ||
: Environment.GetEnvironmentVariable("MSBUILD_EXE_NAME") ?? Constants.MSBuildExecutableName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment says DOTNET_EXPERIMENTAL_HOST_PATH but the code is using MSBUILD_EXE_NAME. Not quite following that bit.
based on: #11393
experimental VS instance https://devdiv.visualstudio.com/DevDiv/_git/VS/pullrequest/616996
This PR contains logic that helps to resolve NetTaskHost execution params based on the project properties.
DOTNET_EXPERIMENTAL_HOST_PATH
=> resolves path to dotnet.exeRuntimeIdentifierGraphPath
=> gives the path to the sdk version resolved for the given project.The values are passed to
NodeProviderOutOfProcTaskHost
by using taskHostParameters.The exception is generated on attempt to use this functionality for sdk9 and lower.
For further flexibility the packet versioning support was added in NodePacketType.
MSBuild Packet Schema with Version Information
Packet Structure Overview
MSBuild's packet communication protocol supports versioning through an extended header mechanism. This document outlines the binary structure of packets with and without version information.
Basic Packet Format
Packet Type Byte (Position 0) Bit Layout
Important Note: Special server command packets (0xF0-0xFF) ignore the extended header flag regardless of its value.
Packet Formats
Standard Packet (No Version Information)
Versioned Packet (With Version Information)
Version Byte Values
Implementation Notes
Migration Strategy
When adding new fields to existing packet types: