Better error messages when makerunnable fails
This commit is contained in:
parent
2e963a6aef
commit
b480eb9072
3 changed files with 48 additions and 33 deletions
|
@ -179,33 +179,40 @@ namespace Microsoft.DotNet.Cli.Compiler.Common
|
|||
|
||||
private static AssemblyReferenceInfo GetAssemblyInfo(LibraryAsset arg)
|
||||
{
|
||||
using (var peReader = new PEReader(File.OpenRead(arg.ResolvedPath)))
|
||||
try
|
||||
{
|
||||
var metadataReader = peReader.GetMetadataReader();
|
||||
|
||||
var definition = metadataReader.GetAssemblyDefinition();
|
||||
|
||||
var identity = new AssemblyIdentity(
|
||||
metadataReader.GetString(definition.Name),
|
||||
definition.Version,
|
||||
metadataReader.GetString(definition.Culture),
|
||||
GetPublicKeyToken(metadataReader.GetBlobBytes(definition.PublicKey))
|
||||
);
|
||||
|
||||
var references = new List<AssemblyIdentity>(metadataReader.AssemblyReferences.Count);
|
||||
|
||||
foreach (var assemblyReferenceHandle in metadataReader.AssemblyReferences)
|
||||
using (var peReader = new PEReader(File.OpenRead(arg.ResolvedPath)))
|
||||
{
|
||||
var assemblyReference = metadataReader.GetAssemblyReference(assemblyReferenceHandle);
|
||||
references.Add(new AssemblyIdentity(
|
||||
metadataReader.GetString(assemblyReference.Name),
|
||||
assemblyReference.Version,
|
||||
metadataReader.GetString(assemblyReference.Culture),
|
||||
GetPublicKeyToken(metadataReader.GetBlobBytes(assemblyReference.PublicKeyOrToken))
|
||||
));
|
||||
}
|
||||
var metadataReader = peReader.GetMetadataReader();
|
||||
|
||||
return new AssemblyReferenceInfo(identity, references.ToArray());
|
||||
var definition = metadataReader.GetAssemblyDefinition();
|
||||
|
||||
var identity = new AssemblyIdentity(
|
||||
metadataReader.GetString(definition.Name),
|
||||
definition.Version,
|
||||
metadataReader.GetString(definition.Culture),
|
||||
GetPublicKeyToken(metadataReader.GetBlobBytes(definition.PublicKey))
|
||||
);
|
||||
|
||||
var references = new List<AssemblyIdentity>(metadataReader.AssemblyReferences.Count);
|
||||
|
||||
foreach (var assemblyReferenceHandle in metadataReader.AssemblyReferences)
|
||||
{
|
||||
var assemblyReference = metadataReader.GetAssemblyReference(assemblyReferenceHandle);
|
||||
references.Add(new AssemblyIdentity(
|
||||
metadataReader.GetString(assemblyReference.Name),
|
||||
assemblyReference.Version,
|
||||
metadataReader.GetString(assemblyReference.Culture),
|
||||
GetPublicKeyToken(metadataReader.GetBlobBytes(assemblyReference.PublicKeyOrToken))
|
||||
));
|
||||
}
|
||||
|
||||
return new AssemblyReferenceInfo(identity, references.ToArray());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new InvalidDataException($"Could not read assembly info for {arg.ResolvedPath}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,8 @@ namespace Microsoft.DotNet.Cli
|
|||
}
|
||||
catch (GracefulException e)
|
||||
{
|
||||
Console.WriteLine(e.Message.Red().Bold());
|
||||
Console.WriteLine(CommandContext.IsVerbose() ? e.ToString().Red().Bold() : e.Message.Red().Bold());
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,17 +116,24 @@ namespace Microsoft.DotNet.Tools.Build
|
|||
|
||||
private void MakeRunnable(ProjectGraphNode graphNode)
|
||||
{
|
||||
var runtimeContext = graphNode.ProjectContext.ProjectFile.HasRuntimeOutput(_args.ConfigValue) ?
|
||||
_args.Workspace.GetRuntimeContext(graphNode.ProjectContext, _args.GetRuntimes()) :
|
||||
graphNode.ProjectContext;
|
||||
try
|
||||
{
|
||||
var runtimeContext = graphNode.ProjectContext.ProjectFile.HasRuntimeOutput(_args.ConfigValue) ?
|
||||
_args.Workspace.GetRuntimeContext(graphNode.ProjectContext, _args.GetRuntimes()) :
|
||||
graphNode.ProjectContext;
|
||||
|
||||
var outputPaths = runtimeContext.GetOutputPaths(_args.ConfigValue, _args.BuildBasePathValue, _args.OutputValue);
|
||||
var libraryExporter = runtimeContext.CreateExporter(_args.ConfigValue, _args.BuildBasePathValue);
|
||||
var outputPaths = runtimeContext.GetOutputPaths(_args.ConfigValue, _args.BuildBasePathValue, _args.OutputValue);
|
||||
var libraryExporter = runtimeContext.CreateExporter(_args.ConfigValue, _args.BuildBasePathValue);
|
||||
|
||||
CopyCompilationOutput(outputPaths);
|
||||
CopyCompilationOutput(outputPaths);
|
||||
|
||||
var executable = new Executable(runtimeContext, outputPaths, libraryExporter, _args.ConfigValue);
|
||||
executable.MakeCompilationOutputRunnable();
|
||||
var executable = new Executable(runtimeContext, outputPaths, libraryExporter, _args.ConfigValue);
|
||||
executable.MakeCompilationOutputRunnable();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"Failed to make the following project runnable: {graphNode.ProjectContext.GetDisplayName()}", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected override CompilationResult RunCompile(ProjectGraphNode projectNode)
|
||||
|
|
Loading…
Reference in a new issue