Remove PackageToProjectFileAdder (#8468)

Add reference to project with version * is doing the same thing
This commit is contained in:
William Lee 2018-01-24 17:55:26 -08:00 committed by GitHub
parent 05052c0541
commit 9e535a867a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 103 deletions

View file

@ -1,12 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.DotNet.ToolPackage
{
internal interface IPackageToProjectFileAdder
{
void Add(FilePath projectPath, string packageId);
}
}

View file

@ -14,7 +14,6 @@ namespace Microsoft.DotNet.ToolPackage
{
private readonly Lazy<string> _bundledTargetFrameworkMoniker;
private readonly Func<FilePath> _getTempProjectPath;
private readonly IPackageToProjectFileAdder _packageToProjectFileAdder;
private readonly IProjectRestorer _projectRestorer;
private readonly DirectoryPath _toolsPath;
private readonly DirectoryPath _offlineFeedPath;
@ -24,15 +23,12 @@ namespace Microsoft.DotNet.ToolPackage
DirectoryPath offlineFeedPath,
Func<FilePath> getTempProjectPath,
Lazy<string> bundledTargetFrameworkMoniker,
IPackageToProjectFileAdder packageToProjectFileAdder,
IProjectRestorer projectRestorer
)
{
_getTempProjectPath = getTempProjectPath;
_bundledTargetFrameworkMoniker = bundledTargetFrameworkMoniker;
_projectRestorer = projectRestorer ?? throw new ArgumentNullException(nameof(projectRestorer));
_packageToProjectFileAdder = packageToProjectFileAdder ??
throw new ArgumentNullException(nameof(packageToProjectFileAdder));
_toolsPath = toolsPath;
_offlineFeedPath = offlineFeedPath;
}
@ -75,14 +71,6 @@ namespace Microsoft.DotNet.ToolPackage
targetframework,
toolDirectory);
if (packageVersionOrPlaceHolder.IsPlaceholder)
{
InvokeAddPackageRestore(
nugetconfig,
tempProjectPath,
packageId);
}
_projectRestorer.Restore(tempProjectPath, toolDirectory, nugetconfig, source);
if (packageVersionOrPlaceHolder.IsPlaceholder)
@ -187,15 +175,13 @@ namespace Microsoft.DotNet.ToolPackage
Directory.Exists(_offlineFeedPath.Value) ? _offlineFeedPath.Value : string.Empty),
new XElement("RestoreAdditionalProjectFallbackFolders", string.Empty), // block other
new XElement("RestoreAdditionalProjectFallbackFoldersExcludes", string.Empty), // block other
new XElement("DisableImplicitNuGetFallbackFolder","true") // disable SDK side implicit NuGetFallbackFolder
),
packageVersion.IsConcreteValue
? new XElement("ItemGroup",
new XElement("PackageReference",
new XAttribute("Include", packageId),
new XAttribute("Version", packageVersion.Value)
new XElement("DisableImplicitNuGetFallbackFolder", "true")), // disable SDK side implicit NuGetFallbackFolder
new XElement("ItemGroup",
new XElement("PackageReference",
new XAttribute("Include", packageId),
new XAttribute("Version", packageVersion.IsConcreteValue ? packageVersion.Value : "*") // nuget will restore * for latest
))
: null));
));
File.WriteAllText(tempProjectPath.Value,
tempProjectContent.ToString());
@ -203,24 +189,6 @@ namespace Microsoft.DotNet.ToolPackage
return tempProjectPath;
}
private void InvokeAddPackageRestore(
FilePath? nugetconfig,
FilePath tempProjectPath,
string packageId)
{
if (nugetconfig != null)
{
File.Copy(
nugetconfig.Value.Value,
tempProjectPath
.GetDirectoryPath()
.WithFile("nuget.config")
.Value);
}
_packageToProjectFileAdder.Add(tempProjectPath, packageId);
}
private DirectoryPath CreateIndividualToolVersionDirectory(
string packageId,
PackageVersion packageVersion)

View file

@ -59,7 +59,6 @@ namespace Microsoft.DotNet.Tools.Install.Tool
.WithSubDirectories(Path.GetRandomFileName())
.WithFile(Path.GetRandomFileName() + ".csproj"),
new Lazy<string>(BundledTargetFramework.GetTargetFrameworkMoniker),
new PackageToProjectFileAdder(),
new ProjectRestorer());
_environmentPathInstruction = environmentPathInstruction

View file

@ -1,47 +0,0 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.ToolPackage;
using Microsoft.DotNet.Tools;
using Microsoft.Extensions.EnvironmentAbstractions;
namespace Microsoft.DotNet.Tools.Install.Tool
{
internal class PackageToProjectFileAdder : IPackageToProjectFileAdder
{
public void Add(FilePath projectPath, string packageId)
{
if (packageId == null)
{
throw new ArgumentNullException(nameof(packageId));
}
var argsToPassToRestore = new List<string>
{
projectPath.Value,
"package",
packageId,
"--no-restore"
};
var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)
.Create(
"add",
argsToPassToRestore)
.CaptureStdOut()
.CaptureStdErr();
var result = command.Execute();
if (result.ExitCode != 0)
{
throw new PackageObtainException(
string.Format(
LocalizableStrings.FailedToAddPackage,
result.StartInfo.WorkingDirectory, result.StartInfo.Arguments, result.StdErr, result.StdOut));
}
}
}
}

View file

@ -29,7 +29,6 @@ namespace Microsoft.DotNet.ToolPackage.Tests
new DirectoryPath("no such path"),
GetUniqueTempProjectPathEachTest,
new Lazy<string>(),
new PackageToProjectFileAdder(),
new ProjectRestorer());
Action a = () => packageObtainer.ObtainAndReturnExecutablePath(
@ -51,7 +50,6 @@ namespace Microsoft.DotNet.ToolPackage.Tests
offlineFeedPath: new DirectoryPath(GetTestLocalFeedPath()),
getTempProjectPath: GetUniqueTempProjectPathEachTest,
bundledTargetFrameworkMoniker: new Lazy<string>(),
packageToProjectFileAdder: new PackageToProjectFileAdder(),
projectRestorer: new ProjectRestorer());
ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath =
@ -173,7 +171,6 @@ namespace Microsoft.DotNet.ToolPackage.Tests
new DirectoryPath("no such path"),
() => uniqueTempProjectPath,
new Lazy<string>(),
new PackageToProjectFileAdder(),
new ProjectRestorer());
}
@ -278,7 +275,6 @@ namespace Microsoft.DotNet.ToolPackage.Tests
new DirectoryPath("no such path"),
GetUniqueTempProjectPathEachTest,
new Lazy<string>(() => BundledTargetFramework.GetTargetFrameworkMoniker()),
new PackageToProjectFileAdder(),
new ProjectRestorer());
}
ToolConfigurationAndExecutablePath toolConfigurationAndExecutablePath =
@ -413,7 +409,6 @@ namespace Microsoft.DotNet.ToolPackage.Tests
new DirectoryPath("no such path"),
GetUniqueTempProjectPathEachTest,
new Lazy<string>(),
new PackageToProjectFileAdder(),
new ProjectRestorer());
}