-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Conversation
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.
49976f0
to
f2d2ac8
Compare
@@ -0,0 +1,55 @@ | |||
//------------------------------------------------------------------------------ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
using Microsoft.Extensions.EnvironmentAbstractions; | ||
|
||
namespace Microsoft.DotNet.ExecutablePackageObtainer |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
string commandName, | ||
string toolAssemblyEntryPoint) | ||
{ | ||
if (string.IsNullOrWhiteSpace(commandName)) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
public class ToolConfigurationAndExecutableDirectory | ||
{ | ||
public ToolConfigurationAndExecutableDirectory( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
$"/p:BaseIntermediateOutputPath={assetJsonOutput.ToEscapedString()}" | ||
}); | ||
|
||
var command = new DotNetCommandFactory(alwaysRunOutOfProc: true) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
"--no-restore" | ||
}; | ||
|
||
var command = new DotNetCommandFactory(alwaysRunOutOfProc: true) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<None Remove="SampleGlobalTool/**" /> | ||
</ItemGroup> | ||
|
||
<Target Name="CreateNupkgFromSource" BeforeTargets="Build"> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@dotnet-bot test Ubuntu x64 Release Build |
901781c
to
5260d00
Compare
src/dotnet/BundledTargetFramework.cs
Outdated
|
||
return NuGetFramework | ||
.Parse(targetFrameworkAttribute.FrameworkName) | ||
.GetShortFolderName(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
public string ToEscapedString() | ||
{ | ||
return $"\"{Value}\""; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
namespace Microsoft.Extensions.EnvironmentAbstractions | ||
{ | ||
public class DirectoryPath |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Value = value; | ||
} | ||
|
||
public DirectoryPath WithCombineFollowing(params string[] paths) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
return new DirectoryPath(Path.Combine(insertValueInFront)); | ||
} | ||
|
||
public FilePath CreateFilePathWithCombineFollowing(string fileName) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
} | ||
|
||
public class FilePath |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
public class ExecutablePackageObtainer | ||
{ | ||
|
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
ToolConfiguration toolConfiguration = | ||
ToolConfigurationDeserializer.Deserialize(toolConfigurationPath.Value); | ||
return toolConfiguration; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
private const string TemporaryProjectTemplate = @"<Project Sdk=""Microsoft.NET.Sdk""> | ||
<PropertyGroup> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
new XElement("RestorePackagesPath", individualToolVersion.Value), | ||
new XElement("DisableImplicitFrameworkReferences", "true") | ||
), | ||
packageVersion.IsConcreteValue |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
} | ||
|
||
public bool IsPlaceHolder { get; } |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
ToolAssemblyEntryPoint = toolAssemblyEntryPoint; | ||
} | ||
|
||
private void EnsureNoInvalidCharacters(string commandName, string nameOfParam) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
public string ToolAssemblyEntryPoint { get; } | ||
} | ||
|
||
public class ToolConfigurationException : ArgumentException |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
{ | ||
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
||
namespace Microsoft.DotNet.Cli | ||
{ | ||
internal class ProjectRestorer : ICanRestoreProject |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
DirectoryPath assetJsonOutput, | ||
FilePath? nugetconfig) | ||
{ | ||
var argsToPassToRestore = new List<string>(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
var result = command.Execute(); | ||
if (result.ExitCode != 0) | ||
{ | ||
throw new PackageObtainException("Failed to restore package. " + |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
public class ExecutablePackageObtainerTests : TestBase | ||
{ | ||
[Fact] | ||
public void GivenNugetConfigAndPackageNameAndVersionAndTargetFrameworkWhenCallItCanDownloadThePacakge() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
[Fact] | ||
public void GivenAllButNoNugetConfigFilePathtCanDownloadThePacakge() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
[Fact] | ||
public void GivenAllButNoPackageVersionItCanDownloadThePacakge() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
} | ||
|
||
[Fact] | ||
public void GivenAllButNoTargetFrameworkItCanDownloadThePacakge() |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<?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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
BeforeTargets="BeforeBuild" | ||
DependsOnTargets="PrepareForBuild"> | ||
|
||
<Target Name="WriteExpectedVersion" BeforeTargets="BeforeBuild" DependsOnTargets="PrepareForBuild"> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
<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.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Resolved all code review, I will squash merge once CI is done @livarcocc @nguerrera |
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:
easily with VSCode. The code is in test csproj.