Merge pull request #5942 from ramarag/mult_Ver
Cache accepting multiple input files
This commit is contained in:
commit
f0e156d384
9 changed files with 135 additions and 27 deletions
|
@ -0,0 +1,3 @@
|
|||
<CacheArtifacts>
|
||||
<Package Id="FluentAssertions" Version ="4.12.0"/>
|
||||
</CacheArtifacts>
|
5
TestAssets/TestProjects/FluentProfile/FluentProfile.xml
Normal file
5
TestAssets/TestProjects/FluentProfile/FluentProfile.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentAssertions" Version ="4.12.0"/>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="NewtonSoft.Json" Version="9.0.1" />
|
||||
<PackageReference Include="FluentAssertions" Version="4.12.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
24
TestAssets/TestProjects/MultiDependentProject/Program.cs
Normal file
24
TestAssets/TestProjects/MultiDependentProject/Program.cs
Normal file
|
@ -0,0 +1,24 @@
|
|||
// 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;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using FluentAssertions;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
ArrayList argList = new ArrayList(args);
|
||||
JObject jObject = new JObject();
|
||||
|
||||
foreach (string arg in argList)
|
||||
{
|
||||
jObject[arg] = arg;
|
||||
}
|
||||
|
||||
jObject.Count.Should().Be(0);
|
||||
Console.WriteLine(jObject.ToString());
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ using Microsoft.DotNet.Cli;
|
|||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Cache
|
||||
{
|
||||
|
@ -31,9 +32,9 @@ namespace Microsoft.DotNet.Tools.Cache
|
|||
app.ArgumentSeparatorHelpText = HelpMessageStrings.MSBuildAdditionalArgsHelpText;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommandOption projectArgument = app.Option(
|
||||
CommandOption projectArguments = app.Option(
|
||||
$"-e|--entries <{LocalizableStrings.ProjectEntries}>", LocalizableStrings.ProjectEntryDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOptionType.MultipleValue);
|
||||
|
||||
CommandOption frameworkOption = app.Option(
|
||||
$"-f|--framework <{LocalizableStrings.FrameworkOption}>", LocalizableStrings.FrameworkOptionDescription,
|
||||
|
@ -70,13 +71,19 @@ namespace Microsoft.DotNet.Tools.Cache
|
|||
{
|
||||
msbuildArgs = new List<string>();
|
||||
|
||||
if (string.IsNullOrEmpty(projectArgument.Value()))
|
||||
if (!projectArguments.HasValue())
|
||||
{
|
||||
throw new InvalidOperationException(LocalizableStrings.SpecifyEntries);
|
||||
}
|
||||
|
||||
msbuildArgs.Add("/t:ComposeCache");
|
||||
msbuildArgs.Add(projectArgument.Value());
|
||||
msbuildArgs.Add(projectArguments.Values[0]);
|
||||
var _additionalProjectsargs = projectArguments.Values.Skip(1);
|
||||
|
||||
if (_additionalProjectsargs.Count() > 0)
|
||||
{
|
||||
msbuildArgs.Add($"/p:AdditionalProjects={string.Join("%3B", _additionalProjectsargs)}");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(frameworkOption.Value()))
|
||||
{
|
||||
|
@ -106,12 +113,12 @@ namespace Microsoft.DotNet.Tools.Cache
|
|||
|
||||
if (skipOptimizationOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:SkipOptimization={skipOptimizationOption.HasValue()}");
|
||||
msbuildArgs.Add($"/p:SkipOptimization=true");
|
||||
}
|
||||
|
||||
if (preserveWorkingDir.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:PreserveComposeWorkingDir={preserveWorkingDir.HasValue()}");
|
||||
msbuildArgs.Add($"/p:PreserveComposeWorkingDir=true");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(verbosityOption.Value()))
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
|
||||
CommandOption filterProjOption = app.Option(
|
||||
$"--filter <{LocalizableStrings.FilterProjOption}>", LocalizableStrings.FilterProjOptionDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOptionType.MultipleValue);
|
||||
|
||||
CommandOption verbosityOption = AddVerbosityOption(app);
|
||||
|
||||
|
@ -95,9 +95,9 @@ namespace Microsoft.DotNet.Tools.Publish
|
|||
msbuildArgs.Add($"/p:VersionSuffix={versionSuffixOption.Value()}");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(filterProjOption.Value()))
|
||||
if (filterProjOption.HasValue())
|
||||
{
|
||||
msbuildArgs.Add($"/p:FilterProjectFiles={filterProjOption.Value()}");
|
||||
msbuildArgs.Add($"/p:FilterProjectFiles={string.Join("%3B", filterProjOption.Values)}");
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(verbosityOption.Value()))
|
||||
|
|
|
@ -3,12 +3,13 @@
|
|||
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using NuGet.Frameworks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public sealed class CacheCommand : TestCommand
|
||||
{
|
||||
private string _profileProject;
|
||||
private List<string> _profileProject = new List<string>();
|
||||
private string _framework;
|
||||
private string _output;
|
||||
private string _runtime;
|
||||
|
@ -22,7 +23,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
public CacheCommand WithEntries(string profileProject)
|
||||
{
|
||||
_profileProject = profileProject;
|
||||
_profileProject.Add($"--entries {profileProject}");
|
||||
|
||||
return this;
|
||||
}
|
||||
public CacheCommand WithFramework(string framework)
|
||||
|
@ -83,7 +85,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
FrameworkVersionOption);
|
||||
}
|
||||
|
||||
private string ProfileProjectOption => string.IsNullOrEmpty(_profileProject) ? "" : $"--entries {_profileProject}";
|
||||
private string ProfileProjectOption => string.Join(" ", _profileProject) ;
|
||||
|
||||
private string FrameworkOption => string.IsNullOrEmpty(_framework) ? "" : $"-f {_framework}";
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using NuGet.Frameworks;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
|
@ -11,7 +12,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
private string _framework;
|
||||
private string _output;
|
||||
private string _runtime;
|
||||
private string _profileproj;
|
||||
private List<string> _profileFilterProject = new List<string>();
|
||||
|
||||
public PublishCommand()
|
||||
: base("dotnet")
|
||||
|
@ -43,7 +44,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
public PublishCommand WithProFileProject(string profileproj)
|
||||
{
|
||||
_profileproj = profileproj;
|
||||
_profileFilterProject.Add( $" --filter {profileproj}");
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -74,6 +75,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
private string RuntimeOption => string.IsNullOrEmpty(_runtime) ? "" : $"-r {_runtime}";
|
||||
|
||||
private string ProfileProjOption => string.IsNullOrEmpty(_profileproj) ? "" : $"--filter {_profileproj}";
|
||||
private string ProfileProjOption => string.Join(" ", _profileFilterProject);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,10 +33,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
|||
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
||||
var localAssemblyCache = Path.Combine(testProjectDirectory, "localAssemblyCache");
|
||||
var intermediateWorkingDirectory = Path.Combine(testProjectDirectory, "workingDirectory");
|
||||
var profileProjectPath = TestAssets.Get(profileProjectName)
|
||||
.CreateInstance()
|
||||
.WithSourceFiles()
|
||||
.Root.FullName;
|
||||
var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName;
|
||||
var profileProject = Path.Combine(profileProjectPath, $"{profileProjectName}.xml");
|
||||
|
||||
new RestoreCommand()
|
||||
|
@ -55,12 +52,12 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
|||
.Should().Pass();
|
||||
|
||||
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
||||
var profilefilter = Path.Combine(localAssemblyCache, _arch, _tfm, "artifact.xml");
|
||||
var profileFilter = Path.Combine(localAssemblyCache, _arch, _tfm, "artifact.xml");
|
||||
|
||||
new PublishCommand()
|
||||
.WithFramework(_tfm)
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.WithProFileProject(profilefilter)
|
||||
.WithProFileProject(profileFilter)
|
||||
.Execute()
|
||||
.Should().Pass();
|
||||
|
||||
|
@ -85,11 +82,8 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
|||
.UseCurrentRuntimeFrameworkVersion();
|
||||
|
||||
var testProjectDirectory = testInstance.Root.ToString();
|
||||
var profileProjectPath = TestAssets.Get(profileProjectName)
|
||||
.CreateInstance()
|
||||
.WithSourceFiles()
|
||||
.Root.FullName;
|
||||
var profileProject = Path.Combine(profileProjectPath, "NewtonsoftFilterProfile.xml");
|
||||
var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName;
|
||||
var profileFilter = Path.Combine(profileProjectPath, "NewtonsoftFilterProfile.xml");
|
||||
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
|
@ -101,7 +95,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
|||
new PublishCommand()
|
||||
.WithFramework(_tfm)
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.WithProFileProject(profileProject)
|
||||
.WithProFileProject(profileFilter)
|
||||
.Execute()
|
||||
.Should().Pass();
|
||||
|
||||
|
@ -112,5 +106,65 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
|
|||
.Should().Fail()
|
||||
.And.HaveStdErrContaining("assembly specified in the dependencies manifest was not found -- package: 'newtonsoft.json',");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItPublishesAnAppWithMultipleProfiles()
|
||||
{
|
||||
var testAppName = "MultiDependentProject";
|
||||
var profileProjectName = "NewtonsoftProfile";
|
||||
var profileProjectName1 = "FluentProfile";
|
||||
|
||||
var testInstance = TestAssets.Get(testAppName)
|
||||
.CreateInstance()
|
||||
.WithSourceFiles()
|
||||
.UseCurrentRuntimeFrameworkVersion();
|
||||
|
||||
var testProjectDirectory = testInstance.Root.ToString();
|
||||
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
||||
var localAssemblyCache = Path.Combine(testProjectDirectory, "lAC");
|
||||
var intermediateWorkingDirectory = Path.Combine(testProjectDirectory, "workingDirectory");
|
||||
|
||||
var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName;
|
||||
var profileProject = Path.Combine(profileProjectPath, $"{profileProjectName}.xml");
|
||||
var profileFilter = Path.Combine(profileProjectPath, "NewtonsoftFilterProfile.xml");
|
||||
|
||||
var profileProjectPath1 = TestAssets.Get(profileProjectName1).Root.FullName;
|
||||
var profileProject1 = Path.Combine(profileProjectPath1, $"{profileProjectName1}.xml");
|
||||
var profileFilter1 = Path.Combine(profileProjectPath1, "FluentFilterProfile.xml");
|
||||
|
||||
new RestoreCommand()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute()
|
||||
.Should().Pass();
|
||||
|
||||
new CacheCommand()
|
||||
.WithEntries(profileProject)
|
||||
.WithEntries(profileProject1)
|
||||
.WithFramework(_tfm)
|
||||
.WithRuntime(rid)
|
||||
.WithOutput(localAssemblyCache)
|
||||
.WithRuntimeFrameworkVersion(_frameworkVersion)
|
||||
.WithIntermediateWorkingDirectory(intermediateWorkingDirectory)
|
||||
.Execute($"--preserve-working-dir")
|
||||
.Should().Pass();
|
||||
|
||||
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
||||
|
||||
new PublishCommand()
|
||||
.WithFramework(_tfm)
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.WithProFileProject(profileFilter)
|
||||
.WithProFileProject(profileFilter1)
|
||||
.Execute()
|
||||
.Should().Pass();
|
||||
|
||||
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");
|
||||
|
||||
new TestCommand("dotnet")
|
||||
.WithEnvironmentVariable("DOTNET_SHARED_PACKAGES", localAssemblyCache)
|
||||
.ExecuteWithCapturedOutput(outputDll)
|
||||
.Should().Pass()
|
||||
.And.HaveStdOutContaining("{}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue