do not set BaseIntermediateOutputPath in temp project of dotnet install (#9122)

Should use MsBuildProjectExtensionsPath instead.

Change the property passin by project file instead of command line. It is more reliable passing path in xml and also the timing of MsBuildProjectExtensionsPath is controlled. (Before loading SDK)
Change mock fake project to use “;” instead, since c:\path contains “:”.
This commit is contained in:
William Li 2018-04-24 10:19:27 -07:00 committed by GitHub
parent 9e877425c4
commit 270fc4428a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 15 deletions

View file

@ -9,7 +9,6 @@ namespace Microsoft.DotNet.ToolPackage
internal interface IProjectRestorer
{
void Restore(FilePath project,
DirectoryPath assetJsonOutput,
FilePath? nugetConfig = null,
string verbosity = null);
}

View file

@ -54,6 +54,7 @@ namespace Microsoft.DotNet.ToolPackage
versionRange: versionRange,
targetFramework: targetFramework ?? BundledTargetFramework.GetTargetFrameworkMoniker(),
restoreDirectory: stageDirectory,
assetJsonOutputDirectory: stageDirectory,
rootConfigDirectory: rootConfigDirectory,
additionalFeeds: additionalFeeds);
@ -61,7 +62,6 @@ namespace Microsoft.DotNet.ToolPackage
{
_projectRestorer.Restore(
tempProject,
stageDirectory,
nugetConfig,
verbosity: verbosity);
}
@ -116,6 +116,7 @@ namespace Microsoft.DotNet.ToolPackage
VersionRange versionRange,
string targetFramework,
DirectoryPath restoreDirectory,
DirectoryPath assetJsonOutputDirectory,
DirectoryPath? rootConfigDirectory,
string[] additionalFeeds)
{
@ -132,7 +133,11 @@ namespace Microsoft.DotNet.ToolPackage
var tempProjectContent = new XDocument(
new XElement("Project",
new XAttribute("Sdk", "Microsoft.NET.Sdk"),
new XElement("PropertyGroup",
new XElement("MsBuildProjectExtensionsPath", assetJsonOutputDirectory.Value)), // change the output directory of asset.json
new XElement(("Import"),
new XAttribute("Project", "Sdk.props"),
new XAttribute("Sdk", "Microsoft.NET.Sdk")),
new XElement("PropertyGroup",
new XElement("TargetFramework", targetFramework),
new XElement("RestorePackagesPath", restoreDirectory.Value),
@ -148,9 +153,10 @@ namespace Microsoft.DotNet.ToolPackage
new XElement("PackageReference",
new XAttribute("Include", packageId.ToString()),
new XAttribute("Version",
versionRange?.ToString("S", new VersionRangeFormatter()) ?? "*") // nuget will restore latest stable for *
))
));
versionRange?.ToString("S", new VersionRangeFormatter()) ?? "*"))), // nuget will restore latest stable for *
new XElement(("Import"),
new XAttribute("Project", "Sdk.targets"),
new XAttribute("Sdk", "Microsoft.NET.Sdk"))));
File.WriteAllText(tempProject.Value, tempProjectContent.ToString());
return tempProject;

View file

@ -27,7 +27,6 @@ namespace Microsoft.DotNet.Tools.Tool.Install
}
public void Restore(FilePath project,
DirectoryPath assetJsonOutput,
FilePath? nugetConfig = null,
string verbosity = null)
{
@ -43,8 +42,7 @@ namespace Microsoft.DotNet.Tools.Tool.Install
argsToPassToRestore.AddRange(new List<string>
{
"--runtime",
AnyRid,
$"-property:BaseIntermediateOutputPath={assetJsonOutput.ToXmlEncodeString()}"
AnyRid
});
argsToPassToRestore.Add($"-verbosity:{verbosity ?? "quiet"}");

View file

@ -57,19 +57,19 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
}
public void Restore(FilePath project,
DirectoryPath assetJsonOutput,
FilePath? nugetConfig = null,
string verbosity = null)
{
string packageId;
VersionRange versionRange;
string targetFramework;
DirectoryPath assetJsonOutput;
try
{
// The mock installer wrote a mock project file containing id:version:framework
// The mock installer wrote a mock project file containing id;version;framework;stageDirectory
var contents = _fileSystem.File.ReadAllText(project.Value);
var tokens = contents.Split(':');
if (tokens.Length != 3)
var tokens = contents.Split(';');
if (tokens.Length != 4)
{
throw new ToolPackageException(LocalizableStrings.ToolInstallationRestoreFailed);
}
@ -77,6 +77,7 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
packageId = tokens[0];
versionRange = VersionRange.Parse(tokens[1]);
targetFramework = tokens[2];
assetJsonOutput = new DirectoryPath(tokens[3]);
}
catch (IOException)
{

View file

@ -63,12 +63,11 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
// Write a fake project with the requested package id, version, and framework
_fileSystem.File.WriteAllText(
tempProject.Value,
$"{packageId}:{versionRange?.ToString("S", new VersionRangeFormatter()) ?? "*"}:{targetFramework}");
$"{packageId};{versionRange?.ToString("S", new VersionRangeFormatter()) ?? "*"};{targetFramework};{stageDirectory.Value}");
// Perform a restore on the fake project
_projectRestorer.Restore(
tempProject,
stageDirectory,
nugetConfig,
verbosity);