Test fixes for tools deps.json generation
This commit is contained in:
parent
fa51bb43fc
commit
5c679cd32e
4 changed files with 36 additions and 4 deletions
|
@ -316,6 +316,12 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
SingleProjectInfo toolLibrary,
|
||||
string toolDepsJsonGeneratorProject)
|
||||
{
|
||||
if (string.IsNullOrEmpty(toolDepsJsonGeneratorProject) ||
|
||||
!File.Exists(toolDepsJsonGeneratorProject))
|
||||
{
|
||||
throw new GracefulException(LocalizableStrings.DepsJsonGeneratorProjectNotSet);
|
||||
}
|
||||
|
||||
Reporter.Verbose.WriteLine(string.Format(
|
||||
LocalizableStrings.GeneratingDepsJson,
|
||||
depsPath));
|
||||
|
@ -332,6 +338,9 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
args.Add($"/p:ToolName={toolLibrary.Name}");
|
||||
args.Add($"/p:ProjectDepsFilePath={tempDepsFile}");
|
||||
|
||||
var toolTargetFramework = toolLockFile.Targets.First().TargetFramework.GetShortFolderName();
|
||||
args.Add($"/p:TargetFramework={toolTargetFramework}");
|
||||
|
||||
|
||||
// Look for the .props file in the Microsoft.NETCore.App package, until NuGet
|
||||
// generates .props and .targets files for tool restores (https://github.com/NuGet/Home/issues/5037)
|
||||
|
@ -364,7 +373,13 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
// will think the deps file is up-to-date and skip executing
|
||||
File.Delete(tempDepsFile);
|
||||
|
||||
var result = new MSBuildForwardingAppWithoutLogging(args).Execute();
|
||||
var msBuildExePath = _environment.GetEnvironmentVariable(Constants.MSBUILD_EXE_PATH);
|
||||
|
||||
msBuildExePath = string.IsNullOrEmpty(msBuildExePath) ?
|
||||
Path.Combine(AppContext.BaseDirectory, "MSBuild.dll") :
|
||||
msBuildExePath;
|
||||
|
||||
var result = new MSBuildForwardingAppWithoutLogging(args, msBuildExePath).Execute();
|
||||
|
||||
if (result != 0)
|
||||
{
|
||||
|
|
|
@ -61,6 +61,8 @@ namespace Microsoft.DotNet.Cli.Utils
|
|||
|
||||
public const string UnableToGenerateDepsJson = "unable to generate deps.json, it may have been already generated: {0}";
|
||||
|
||||
public const string DepsJsonGeneratorProjectNotSet = "Unable to find deps.json generator project.";
|
||||
|
||||
public const string UnableToDeleteTemporaryDepsJson = "unable to delete temporary deps.json file: {0}";
|
||||
|
||||
public const string VersionForPackageCouldNotBeResolved = "Version for package `{0}` could not be resolved.";
|
||||
|
|
|
@ -281,7 +281,8 @@ namespace Microsoft.DotNet.Tests
|
|||
lockFile,
|
||||
s_toolPackageFramework,
|
||||
depsJsonFile,
|
||||
new SingleProjectInfo("dotnet-portable", "1.0.0", Enumerable.Empty<ResourceAssemblyInfo>()));
|
||||
new SingleProjectInfo("dotnet-portable", "1.0.0", Enumerable.Empty<ResourceAssemblyInfo>()),
|
||||
GetToolDepsJsonGeneratorProject());
|
||||
|
||||
File.ReadAllText(depsJsonFile).Should().Be("temp");
|
||||
File.Delete(depsJsonFile);
|
||||
|
@ -456,5 +457,12 @@ namespace Microsoft.DotNet.Tests
|
|||
|
||||
return projectToolsCommandResolver;
|
||||
}
|
||||
|
||||
private string GetToolDepsJsonGeneratorProject()
|
||||
{
|
||||
// When using the product, the ToolDepsJsonGeneratorProject property is used to get this path, but for testing
|
||||
// we'll hard code the path inside the SDK since we don't have a project to evaluate here
|
||||
return Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, @"Sdks\Microsoft.NET.Sdk\build\GenerateDeps\GenerateDeps.proj");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ using NuGet.Protocol;
|
|||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
using MSBuildCommand = Microsoft.DotNet.Tools.Test.Utilities.MSBuildCommand;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
||||
{
|
||||
|
@ -164,11 +166,16 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
|
|||
|
||||
MSBuildForwardingApp msBuildForwardingApp = new MSBuildForwardingApp(Enumerable.Empty<string>());
|
||||
|
||||
FieldInfo forwardingAppFieldInfo = msBuildForwardingApp
|
||||
object forwardingAppWithoutLogging = msBuildForwardingApp
|
||||
.GetType()
|
||||
.GetField("_forwardingAppWithoutLogging", BindingFlags.Instance | BindingFlags.NonPublic)
|
||||
?.GetValue(msBuildForwardingApp);
|
||||
|
||||
FieldInfo forwardingAppFieldInfo = forwardingAppWithoutLogging
|
||||
.GetType()
|
||||
.GetField("_forwardingApp", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
ForwardingApp forwardingApp = forwardingAppFieldInfo?.GetValue(msBuildForwardingApp) as ForwardingApp;
|
||||
object forwardingApp = forwardingAppFieldInfo?.GetValue(forwardingAppWithoutLogging);
|
||||
|
||||
FieldInfo allArgsFieldinfo = forwardingApp?
|
||||
.GetType()
|
||||
|
|
Loading…
Reference in a new issue