-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix build host when only the .net 6 SDK is installed #73818
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,76 +24,85 @@ | |
return ExitFailure; | ||
} | ||
|
||
using var pipeClient = new AnonymousPipeClientStream(PipeDirection.In, args[0]); | ||
using var sr = new StreamReader(pipeClient); | ||
string? output; | ||
|
||
// Wait for 'sync message' from the server. | ||
do | ||
try | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar change to ensure exception details are captured if something goes wrong. |
||
{ | ||
output = await sr.ReadLineAsync().ConfigureAwait(false); | ||
} | ||
while (!(output?.StartsWith("ASSEMBLY", StringComparison.OrdinalIgnoreCase) == true)); | ||
using var pipeClient = new AnonymousPipeClientStream(PipeDirection.In, args[0]); | ||
using var sr = new StreamReader(pipeClient); | ||
string? output; | ||
|
||
if ((output = await sr.ReadLineAsync().ConfigureAwait(false)) is not null) | ||
{ | ||
var assemblyFileName = output; | ||
// Wait for 'sync message' from the server. | ||
do | ||
{ | ||
output = await sr.ReadLineAsync().ConfigureAwait(false); | ||
} | ||
while (!(output?.StartsWith("ASSEMBLY", StringComparison.OrdinalIgnoreCase) == true)); | ||
|
||
#if NET6_0_OR_GREATER | ||
var resolver = new System.Runtime.Loader.AssemblyDependencyResolver(assemblyFileName); | ||
System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += (context, assemblyName) => | ||
if ((output = await sr.ReadLineAsync().ConfigureAwait(false)) is not null) | ||
{ | ||
var assemblyPath = resolver.ResolveAssemblyToPath(assemblyName); | ||
if (assemblyPath is not null) | ||
var assemblyFileName = output; | ||
|
||
#if NET6_0_OR_GREATER | ||
var resolver = new System.Runtime.Loader.AssemblyDependencyResolver(assemblyFileName); | ||
System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += (context, assemblyName) => | ||
{ | ||
return context.LoadFromAssemblyPath(assemblyPath); | ||
} | ||
var assemblyPath = resolver.ResolveAssemblyToPath(assemblyName); | ||
if (assemblyPath is not null) | ||
{ | ||
return context.LoadFromAssemblyPath(assemblyPath); | ||
} | ||
|
||
return null; | ||
}; | ||
return null; | ||
}; | ||
#endif | ||
|
||
string testDescriptor = Path.GetFileName(assemblyFileName); | ||
string testDescriptor = Path.GetFileName(assemblyFileName); | ||
#if NET | ||
testDescriptor += " (.NET Core)"; | ||
testDescriptor += " (.NET Core)"; | ||
#else | ||
testDescriptor += " (.NET Framework)"; | ||
#endif | ||
|
||
await Console.Out.WriteLineAsync($"Discovering tests in {testDescriptor}...").ConfigureAwait(false); | ||
await Console.Out.WriteLineAsync($"Discovering tests in {testDescriptor}...").ConfigureAwait(false); | ||
|
||
using var xunit = new XunitFrontController(AppDomainSupport.IfAvailable, assemblyFileName, shadowCopy: false); | ||
var configuration = ConfigReader.Load(assemblyFileName); | ||
var sink = new Sink(); | ||
xunit.Find(includeSourceInformation: false, | ||
messageSink: sink, | ||
discoveryOptions: TestFrameworkOptions.ForDiscovery(configuration)); | ||
using var xunit = new XunitFrontController(AppDomainSupport.IfAvailable, assemblyFileName, shadowCopy: false); | ||
var configuration = ConfigReader.Load(assemblyFileName); | ||
var sink = new Sink(); | ||
xunit.Find(includeSourceInformation: false, | ||
messageSink: sink, | ||
discoveryOptions: TestFrameworkOptions.ForDiscovery(configuration)); | ||
|
||
var testsToWrite = new HashSet<string>(); | ||
await foreach (var fullyQualifiedName in sink.GetTestCaseNamesAsync()) | ||
{ | ||
testsToWrite.Add(fullyQualifiedName); | ||
} | ||
var testsToWrite = new HashSet<string>(); | ||
await foreach (var fullyQualifiedName in sink.GetTestCaseNamesAsync()) | ||
{ | ||
testsToWrite.Add(fullyQualifiedName); | ||
} | ||
|
||
if (sink.AnyWriteFailures) | ||
{ | ||
await Console.Error.WriteLineAsync($"Channel failed to write for '{assemblyFileName}'").ConfigureAwait(false); | ||
return ExitFailure; | ||
} | ||
if (sink.AnyWriteFailures) | ||
{ | ||
await Console.Error.WriteLineAsync($"Channel failed to write for '{assemblyFileName}'").ConfigureAwait(false); | ||
return ExitFailure; | ||
} | ||
|
||
#if NET6_0_OR_GREATER | ||
await Console.Out.WriteLineAsync($"Discovered {testsToWrite.Count} tests in {testDescriptor}").ConfigureAwait(false); | ||
await Console.Out.WriteLineAsync($"Discovered {testsToWrite.Count} tests in {testDescriptor}").ConfigureAwait(false); | ||
#else | ||
await Console.Out.WriteLineAsync($"Discovered {testsToWrite.Count} tests in {testDescriptor}").ConfigureAwait(false); | ||
await Console.Out.WriteLineAsync($"Discovered {testsToWrite.Count} tests in {testDescriptor}").ConfigureAwait(false); | ||
#endif | ||
|
||
var directory = Path.GetDirectoryName(assemblyFileName); | ||
using var fileStream = File.Create(Path.Combine(directory!, "testlist.json")); | ||
await JsonSerializer.SerializeAsync(fileStream, testsToWrite).ConfigureAwait(false); | ||
return ExitSuccess; | ||
} | ||
var directory = Path.GetDirectoryName(assemblyFileName); | ||
using var fileStream = File.Create(Path.Combine(directory!, "testlist.json")); | ||
await JsonSerializer.SerializeAsync(fileStream, testsToWrite).ConfigureAwait(false); | ||
return ExitSuccess; | ||
} | ||
|
||
return ExitFailure; | ||
return ExitFailure; | ||
} | ||
catch (Exception ex) | ||
{ | ||
// Write the exception details to stderr so the host process can pick it up. | ||
await Console.Error.WriteLineAsync(ex.ToString()).ConfigureAwait(false); | ||
return 1; | ||
} | ||
|
||
file class Sink : IMessageSink | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
errors were getting swallowed so it was just failing with no info. this ensures error output from the discovery worker is captured