Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Global tools package obtain #8035

Merged
merged 20 commits into from
Nov 22, 2017
Merged

Conversation

wli3
Copy link

@wli3 wli3 commented Nov 16, 2017

This is a model. It is not used by dotnet.dll yet for easy code review. Given a tools package id, it can create a fake project and restore to correct folder

Includes:

  • DI, aka no circular dependency of commands
  • Parser of config XML
  • I try to create test nupkg at build time, so I can run test and debug
    easily with VSCode. The code is in test csproj.

Given a tools package id, it can create a fake project and restore to correct folder

Includes:
- DI, aka no circular dependency of commands
- Parser of config XML
= I try to create test nupkg at build time, so I can run test and debug
easily with VSCode. The code is in test csproj.
@wli3 wli3 force-pushed the global-tools-package-obtain branch from 49976f0 to f2d2ac8 Compare November 16, 2017 17:11
@@ -0,0 +1,55 @@
//------------------------------------------------------------------------------

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


using Microsoft.Extensions.EnvironmentAbstractions;

namespace Microsoft.DotNet.ExecutablePackageObtainer

This comment was marked as spam.

string commandName,
string toolAssemblyEntryPoint)
{
if (string.IsNullOrWhiteSpace(commandName))

This comment was marked as spam.

{
public class ToolConfigurationAndExecutableDirectory
{
public ToolConfigurationAndExecutableDirectory(

This comment was marked as spam.

$"/p:BaseIntermediateOutputPath={assetJsonOutput.ToEscapedString()}"
});

var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)

This comment was marked as spam.

"--no-restore"
};

var command = new DotNetCommandFactory(alwaysRunOutOfProc: true)

This comment was marked as spam.

var result = command.Execute();
if (result.ExitCode != 0)
{
throw new PackageObtainException("Failed to add package. " +

This comment was marked as spam.

This comment was marked as spam.

<None Remove="SampleGlobalTool/**" />
</ItemGroup>

<Target Name="CreateNupkgFromSource" BeforeTargets="Build">

This comment was marked as spam.

This comment was marked as spam.

@wli3 wli3 changed the title WIP Global tools package obtain Global tools package obtain Nov 16, 2017
<ProjectReference Include="..\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
<ProjectReference Include="..\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
</ItemGroup>
</Project>

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@wli3
Copy link
Author

wli3 commented Nov 17, 2017

@dotnet-bot test Ubuntu x64 Release Build

@wli3 wli3 force-pushed the global-tools-package-obtain branch from 901781c to 5260d00 Compare November 17, 2017 04:00

return NuGetFramework
.Parse(targetFrameworkAttribute.FrameworkName)
.GetShortFolderName();

This comment was marked as spam.

This comment was marked as spam.


public string ToEscapedString()
{
return $"\"{Value}\"";

This comment was marked as spam.

This comment was marked as spam.


namespace Microsoft.Extensions.EnvironmentAbstractions
{
public class DirectoryPath

This comment was marked as spam.

This comment was marked as spam.

Value = value;
}

public DirectoryPath WithCombineFollowing(params string[] paths)

This comment was marked as spam.

This comment was marked as spam.

return new DirectoryPath(Path.Combine(insertValueInFront));
}

public FilePath CreateFilePathWithCombineFollowing(string fileName)

This comment was marked as spam.

This comment was marked as spam.

}
}

public class FilePath

This comment was marked as spam.

This comment was marked as spam.

{
public class ExecutablePackageObtainer
{

This comment was marked as spam.

This comment was marked as spam.


ToolConfiguration toolConfiguration =
ToolConfigurationDeserializer.Deserialize(toolConfigurationPath.Value);
return toolConfiguration;

This comment was marked as spam.

This comment was marked as spam.

}

private const string TemporaryProjectTemplate = @"<Project Sdk=""Microsoft.NET.Sdk"">
<PropertyGroup>

This comment was marked as spam.

This comment was marked as spam.

@@ -0,0 +1,13 @@
// 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.

This comment was marked as spam.

This comment was marked as spam.

FilePath? nugetconfig = null,
string targetframework = null)
{
if (packageId == null) throw new ArgumentNullException(nameof(packageId));

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

new XElement("RestorePackagesPath", individualToolVersion.Value),
new XElement("DisableImplicitFrameworkReferences", "true")
),
packageVersion.IsConcreteValue

This comment was marked as spam.

This comment was marked as spam.

}
}

public bool IsPlaceHolder { get; }

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

ToolAssemblyEntryPoint = toolAssemblyEntryPoint;
}

private void EnsureNoInvalidCharacters(string commandName, string nameOfParam)

This comment was marked as spam.

This comment was marked as spam.

public string ToolAssemblyEntryPoint { get; }
}

public class ToolConfigurationException : ArgumentException

This comment was marked as spam.

This comment was marked as spam.

{
public void Add(FilePath projectPath, string packageId)
{
if (packageId == null) throw new ArgumentNullException(nameof(packageId));

This comment was marked as spam.

This comment was marked as spam.

var result = command.Execute();
if (result.ExitCode != 0)
{
throw new PackageObtainException("Failed to add package. " +

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


namespace Microsoft.DotNet.Cli
{
internal class ProjectRestorer : ICanRestoreProject

This comment was marked as spam.

This comment was marked as spam.

DirectoryPath assetJsonOutput,
FilePath? nugetconfig)
{
var argsToPassToRestore = new List<string>();

This comment was marked as spam.

This comment was marked as spam.

var result = command.Execute();
if (result.ExitCode != 0)
{
throw new PackageObtainException("Failed to restore package. " +

This comment was marked as spam.

public class ExecutablePackageObtainerTests : TestBase
{
[Fact]
public void GivenNugetConfigAndPackageNameAndVersionAndTargetFrameworkWhenCallItCanDownloadThePacakge()

This comment was marked as spam.

This comment was marked as spam.

}

[Fact]
public void GivenAllButNoNugetConfigFilePathtCanDownloadThePacakge()

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

var toolsPath = Path.Combine(Directory.GetCurrentDirectory(), Path.GetRandomFileName());

Directory.CreateDirectory(tempProjectDirectory.Value);
File.Copy(nugetConfigPath.Value,

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

}

[Fact]
public void GivenAllButNoPackageVersionItCanDownloadThePacakge()

This comment was marked as spam.

This comment was marked as spam.

}

[Fact]
public void GivenAllButNoTargetFrameworkItCanDownloadThePacakge()

This comment was marked as spam.

This comment was marked as spam.

<?xml version="1.0" encoding="utf-8" ?>
<DotnetToolMetadata>
<CommandName>sayhello</CommandName>
<ToolAssemblyEntryPoint>consoleappababab.dll</ToolAssemblyEntryPoint>

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

BeforeTargets="BeforeBuild"
DependsOnTargets="PrepareForBuild">

<Target Name="WriteExpectedVersion" BeforeTargets="BeforeBuild" DependsOnTargets="PrepareForBuild">

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

<ItemGroup>
<Content Include="$(ExpectedVersionFileInIntermediateFolder)" CopyToOutputDirectory="PreserveNewest" />
<FileWrites Include="$(ExpectedVersionFileInIntermediateFolder)" />
</ItemGroup>
</Target>

<Target Name="WriteExpectedTargetFrameworkMoniker" BeforeTargets="BeforeBuild" DependsOnTargets="PrepareForBuild">

This comment was marked as spam.

This comment was marked as spam.

@wli3
Copy link
Author

wli3 commented Nov 22, 2017

Resolved all code review, I will squash merge once CI is done @livarcocc @nguerrera

@wli3 wli3 merged commit 584d3f0 into dotnet:master Nov 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants