Skip to content
Permalink
Browse files

[NuGet] Improve logging if restore failed

  • Loading branch information
xen2 committed Nov 27, 2018
1 parent f0341a7 commit 7793e1f757189e811b5692c8ed750ef314548aa5
@@ -16,6 +16,7 @@
<AssemblyName>Xenko.GameStudio</AssemblyName>
<XenkoAssemblyProcessor>true</XenkoAssemblyProcessor>
<XenkoAssemblyProcessorOptions>--auto-module-initializer</XenkoAssemblyProcessorOptions>
<DefineConstants>XENKO_NUGET_RESOLVER_UX;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>x64</PlatformTarget>
@@ -27,7 +28,6 @@
<PlatformTarget>x64</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineConstants>TRACE</DefineConstants>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
@@ -60,13 +60,40 @@ internal static void __Initialize__()
assembliesResolved = true;

var logger = new Logger();
var (request, result) = RestoreHelper.Restore(logger, Assembly.GetExecutingAssembly().GetName().Name, new VersionRange(new NuGetVersion(XenkoVersion.NuGetVersion))).Result;
if (!result.Success)
try
{
throw new InvalidOperationException($"Could not restore NuGet packages:{Environment.NewLine}{Environment.NewLine}{string.Join(Environment.NewLine, logger.Logs.Where(x => x.Level >= LogLevel.Warning).Select(x => $"[{x.Level}] {x.Message}"))}");
}
var (request, result) = RestoreHelper.Restore(logger, Assembly.GetExecutingAssembly().GetName().Name, new VersionRange(new NuGetVersion(XenkoVersion.NuGetVersion))).Result;
if (!result.Success)
{
throw new InvalidOperationException($"Could not restore NuGet packages");
}

assemblies = RestoreHelper.ListAssemblies(request, result);
assemblies = RestoreHelper.ListAssemblies(request, result);
}
catch (Exception e)
{
var logFile = Path.GetTempPath() + Guid.NewGuid().ToString() + ".txt";
var logText = $@"Error restoring NuGet packages!
==== Exception details ====
{e}
==== Log ====
{string.Join(Environment.NewLine, logger.Logs.Select(x => $"[{x.Level}] {x.Message}"))}
";
File.WriteAllText(logFile, logText);
#if XENKO_NUGET_RESOLVER_UX
// Write log to file
System.Windows.Forms.MessageBox.Show($"{e.Message}{Environment.NewLine}{Environment.NewLine}Please see details in {logFile} (which will be automatically opened)", "Error restoring NuGet packages");
Process.Start(logFile);
#else
// Display log in console
Console.WriteLine(logText);
#endif
Environment.Exit(1);
}
}
}

@@ -9,6 +9,7 @@
<XenkoBuildTags>WindowsTools</XenkoBuildTags>
<XenkoAssemblyProcessor>true</XenkoAssemblyProcessor>
<XenkoAssemblyProcessorOptions>--auto-module-initializer</XenkoAssemblyProcessorOptions>
<DefineConstants>XENKO_NUGET_RESOLVER_UX;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<Prefer32Bit>false</Prefer32Bit>

0 comments on commit 7793e1f

Please sign in to comment.
You can’t perform that action at this time.