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:
parent
9e877425c4
commit
270fc4428a
5 changed files with 18 additions and 15 deletions
|
@ -9,7 +9,6 @@ namespace Microsoft.DotNet.ToolPackage
|
||||||
internal interface IProjectRestorer
|
internal interface IProjectRestorer
|
||||||
{
|
{
|
||||||
void Restore(FilePath project,
|
void Restore(FilePath project,
|
||||||
DirectoryPath assetJsonOutput,
|
|
||||||
FilePath? nugetConfig = null,
|
FilePath? nugetConfig = null,
|
||||||
string verbosity = null);
|
string verbosity = null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ namespace Microsoft.DotNet.ToolPackage
|
||||||
versionRange: versionRange,
|
versionRange: versionRange,
|
||||||
targetFramework: targetFramework ?? BundledTargetFramework.GetTargetFrameworkMoniker(),
|
targetFramework: targetFramework ?? BundledTargetFramework.GetTargetFrameworkMoniker(),
|
||||||
restoreDirectory: stageDirectory,
|
restoreDirectory: stageDirectory,
|
||||||
|
assetJsonOutputDirectory: stageDirectory,
|
||||||
rootConfigDirectory: rootConfigDirectory,
|
rootConfigDirectory: rootConfigDirectory,
|
||||||
additionalFeeds: additionalFeeds);
|
additionalFeeds: additionalFeeds);
|
||||||
|
|
||||||
|
@ -61,7 +62,6 @@ namespace Microsoft.DotNet.ToolPackage
|
||||||
{
|
{
|
||||||
_projectRestorer.Restore(
|
_projectRestorer.Restore(
|
||||||
tempProject,
|
tempProject,
|
||||||
stageDirectory,
|
|
||||||
nugetConfig,
|
nugetConfig,
|
||||||
verbosity: verbosity);
|
verbosity: verbosity);
|
||||||
}
|
}
|
||||||
|
@ -116,6 +116,7 @@ namespace Microsoft.DotNet.ToolPackage
|
||||||
VersionRange versionRange,
|
VersionRange versionRange,
|
||||||
string targetFramework,
|
string targetFramework,
|
||||||
DirectoryPath restoreDirectory,
|
DirectoryPath restoreDirectory,
|
||||||
|
DirectoryPath assetJsonOutputDirectory,
|
||||||
DirectoryPath? rootConfigDirectory,
|
DirectoryPath? rootConfigDirectory,
|
||||||
string[] additionalFeeds)
|
string[] additionalFeeds)
|
||||||
{
|
{
|
||||||
|
@ -132,7 +133,11 @@ namespace Microsoft.DotNet.ToolPackage
|
||||||
|
|
||||||
var tempProjectContent = new XDocument(
|
var tempProjectContent = new XDocument(
|
||||||
new XElement("Project",
|
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("PropertyGroup",
|
||||||
new XElement("TargetFramework", targetFramework),
|
new XElement("TargetFramework", targetFramework),
|
||||||
new XElement("RestorePackagesPath", restoreDirectory.Value),
|
new XElement("RestorePackagesPath", restoreDirectory.Value),
|
||||||
|
@ -148,9 +153,10 @@ namespace Microsoft.DotNet.ToolPackage
|
||||||
new XElement("PackageReference",
|
new XElement("PackageReference",
|
||||||
new XAttribute("Include", packageId.ToString()),
|
new XAttribute("Include", packageId.ToString()),
|
||||||
new XAttribute("Version",
|
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());
|
File.WriteAllText(tempProject.Value, tempProjectContent.ToString());
|
||||||
return tempProject;
|
return tempProject;
|
||||||
|
|
|
@ -27,7 +27,6 @@ namespace Microsoft.DotNet.Tools.Tool.Install
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Restore(FilePath project,
|
public void Restore(FilePath project,
|
||||||
DirectoryPath assetJsonOutput,
|
|
||||||
FilePath? nugetConfig = null,
|
FilePath? nugetConfig = null,
|
||||||
string verbosity = null)
|
string verbosity = null)
|
||||||
{
|
{
|
||||||
|
@ -43,8 +42,7 @@ namespace Microsoft.DotNet.Tools.Tool.Install
|
||||||
argsToPassToRestore.AddRange(new List<string>
|
argsToPassToRestore.AddRange(new List<string>
|
||||||
{
|
{
|
||||||
"--runtime",
|
"--runtime",
|
||||||
AnyRid,
|
AnyRid
|
||||||
$"-property:BaseIntermediateOutputPath={assetJsonOutput.ToXmlEncodeString()}"
|
|
||||||
});
|
});
|
||||||
|
|
||||||
argsToPassToRestore.Add($"-verbosity:{verbosity ?? "quiet"}");
|
argsToPassToRestore.Add($"-verbosity:{verbosity ?? "quiet"}");
|
||||||
|
|
|
@ -57,19 +57,19 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Restore(FilePath project,
|
public void Restore(FilePath project,
|
||||||
DirectoryPath assetJsonOutput,
|
|
||||||
FilePath? nugetConfig = null,
|
FilePath? nugetConfig = null,
|
||||||
string verbosity = null)
|
string verbosity = null)
|
||||||
{
|
{
|
||||||
string packageId;
|
string packageId;
|
||||||
VersionRange versionRange;
|
VersionRange versionRange;
|
||||||
string targetFramework;
|
string targetFramework;
|
||||||
|
DirectoryPath assetJsonOutput;
|
||||||
try
|
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 contents = _fileSystem.File.ReadAllText(project.Value);
|
||||||
var tokens = contents.Split(':');
|
var tokens = contents.Split(';');
|
||||||
if (tokens.Length != 3)
|
if (tokens.Length != 4)
|
||||||
{
|
{
|
||||||
throw new ToolPackageException(LocalizableStrings.ToolInstallationRestoreFailed);
|
throw new ToolPackageException(LocalizableStrings.ToolInstallationRestoreFailed);
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
||||||
packageId = tokens[0];
|
packageId = tokens[0];
|
||||||
versionRange = VersionRange.Parse(tokens[1]);
|
versionRange = VersionRange.Parse(tokens[1]);
|
||||||
targetFramework = tokens[2];
|
targetFramework = tokens[2];
|
||||||
|
assetJsonOutput = new DirectoryPath(tokens[3]);
|
||||||
}
|
}
|
||||||
catch (IOException)
|
catch (IOException)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,12 +63,11 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
||||||
// Write a fake project with the requested package id, version, and framework
|
// Write a fake project with the requested package id, version, and framework
|
||||||
_fileSystem.File.WriteAllText(
|
_fileSystem.File.WriteAllText(
|
||||||
tempProject.Value,
|
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
|
// Perform a restore on the fake project
|
||||||
_projectRestorer.Restore(
|
_projectRestorer.Restore(
|
||||||
tempProject,
|
tempProject,
|
||||||
stageDirectory,
|
|
||||||
nugetConfig,
|
nugetConfig,
|
||||||
verbosity);
|
verbosity);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue