Making OutputPathCommandResolver work with MSBuild.
This commit is contained in:
parent
cde0e8e7e8
commit
d61ebd3087
7 changed files with 126 additions and 34 deletions
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.NET.Sdk">
|
||||||
|
<Version>1.0.0-alpha-20161019-1</Version>
|
||||||
|
<PrivateAssets>All</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="dotnet-desktop-and-portable">
|
||||||
|
<Version>1.0.0-*</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
|
||||||
|
<PackageReference Include="Microsoft.NETCore.App">
|
||||||
|
<Version>1.0.1</Version>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<DotNetCliToolReference Include="dotnet-dependency-tool-invoker">
|
||||||
|
<Version>1.0.0-*</Version>
|
||||||
|
</DotNetCliToolReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="**\*.cs" />
|
||||||
|
<EmbeddedResource Include="**\*.resx" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace ConsoleApplication
|
||||||
|
{
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main()
|
||||||
|
{
|
||||||
|
Console.WriteLine("Hello World!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -16,6 +16,8 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
|
|
||||||
string RuntimeConfigJsonPath { get; }
|
string RuntimeConfigJsonPath { get; }
|
||||||
|
|
||||||
|
string OutputPath { get; }
|
||||||
|
|
||||||
Dictionary<string, string> EnvironmentVariables { get; }
|
Dictionary<string, string> EnvironmentVariables { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -39,6 +39,17 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string OutputPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _project
|
||||||
|
.AllEvaluatedProperties
|
||||||
|
.FirstOrDefault(p => p.Name.Equals("TargetDir"))
|
||||||
|
.EvaluatedValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Dictionary<string, string> EnvironmentVariables
|
public Dictionary<string, string> EnvironmentVariables
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -42,19 +42,22 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
string outputPath,
|
string outputPath,
|
||||||
string buildBasePath)
|
string buildBasePath)
|
||||||
{
|
{
|
||||||
var projectContext = GetProjectContextFromDirectory(
|
var projectFactory = new ProjectFactory(_environment);
|
||||||
|
var project = projectFactory.GetProject(
|
||||||
projectDirectory,
|
projectDirectory,
|
||||||
framework);
|
framework,
|
||||||
|
configuration,
|
||||||
|
buildBasePath,
|
||||||
|
outputPath);
|
||||||
|
|
||||||
if (projectContext == null)
|
if (project == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var buildOutputPath =
|
var buildOutputPath = project.OutputPath;
|
||||||
projectContext.GetOutputPaths(configuration, buildBasePath, outputPath).RuntimeFiles.BasePath;
|
|
||||||
|
|
||||||
if (! Directory.Exists(buildOutputPath))
|
if (!Directory.Exists(buildOutputPath))
|
||||||
{
|
{
|
||||||
Reporter.Verbose.WriteLine($"outputpathresolver: {buildOutputPath} does not exist");
|
Reporter.Verbose.WriteLine($"outputpathresolver: {buildOutputPath} does not exist");
|
||||||
return null;
|
return null;
|
||||||
|
@ -63,33 +66,6 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
return _environment.GetCommandPathFromRootPath(buildOutputPath, commandName);
|
return _environment.GetCommandPathFromRootPath(buildOutputPath, commandName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjectContext GetProjectContextFromDirectory(string directory, NuGetFramework framework)
|
|
||||||
{
|
|
||||||
if (directory == null || framework == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var projectRootPath = directory;
|
|
||||||
|
|
||||||
if (!File.Exists(Path.Combine(projectRootPath, Project.FileName)))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var projectContext = ProjectContext.Create(
|
|
||||||
projectRootPath,
|
|
||||||
framework,
|
|
||||||
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
|
|
||||||
|
|
||||||
if (projectContext.RuntimeIdentifier == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return projectContext;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal override CommandResolutionStrategy GetCommandResolutionStrategy()
|
internal override CommandResolutionStrategy GetCommandResolutionStrategy()
|
||||||
{
|
{
|
||||||
return CommandResolutionStrategy.OutputPath;
|
return CommandResolutionStrategy.OutputPath;
|
||||||
|
|
|
@ -67,6 +67,15 @@ namespace Microsoft.DotNet.Cli.Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string OutputPath
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return
|
||||||
|
ProjectContext.GetOutputPaths(_configuration, _buildBasePath, _outputPath).RuntimeFiles.BasePath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Dictionary<string, string> EnvironmentVariables
|
public Dictionary<string, string> EnvironmentVariables
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
// 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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
|
@ -15,6 +16,16 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
{
|
{
|
||||||
private static readonly NuGetFramework s_desktopTestFramework = FrameworkConstants.CommonFrameworks.Net451;
|
private static readonly NuGetFramework s_desktopTestFramework = FrameworkConstants.CommonFrameworks.Net451;
|
||||||
|
|
||||||
|
private RepoDirectoriesProvider _repoDirectoriesProvider;
|
||||||
|
|
||||||
|
public GivenAProjectDependenciesCommandFactory()
|
||||||
|
{
|
||||||
|
_repoDirectoriesProvider = new RepoDirectoriesProvider();
|
||||||
|
Environment.SetEnvironmentVariable(
|
||||||
|
Constants.MSBUILD_EXE_PATH,
|
||||||
|
Path.Combine(_repoDirectoriesProvider.Stage2Sdk, "MSBuild.dll"));
|
||||||
|
}
|
||||||
|
|
||||||
[WindowsOnlyFact]
|
[WindowsOnlyFact]
|
||||||
public void It_resolves_desktop_apps_defaulting_to_Debug_Configuration()
|
public void It_resolves_desktop_apps_defaulting_to_Debug_Configuration()
|
||||||
{
|
{
|
||||||
|
@ -46,6 +57,40 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
|
Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[WindowsOnlyFact]
|
||||||
|
public void It_resolves_desktop_apps_with_MSBuild_defaulting_to_Debug_Configuration()
|
||||||
|
{
|
||||||
|
var configuration = "Debug";
|
||||||
|
|
||||||
|
var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "TestProjects"));
|
||||||
|
var testInstance = testAssetManager.CreateTestInstance("MSBuildAppWithMultipleFrameworksAndTools", "i")
|
||||||
|
.WithLockFiles();
|
||||||
|
|
||||||
|
var projectFile = Path.Combine(testInstance.TestRoot, "MSBuildAppWithMultipleFrameworksAndTools.csproj");
|
||||||
|
|
||||||
|
new Restore3Command()
|
||||||
|
.ExecuteWithCapturedOutput($"{projectFile} -s {_repoDirectoriesProvider.TestPackages}")
|
||||||
|
.Should()
|
||||||
|
.Pass();
|
||||||
|
|
||||||
|
new Build3Command()
|
||||||
|
.Execute($"{projectFile} --configuration {configuration}")
|
||||||
|
.Should()
|
||||||
|
.Pass();
|
||||||
|
|
||||||
|
var factory = new ProjectDependenciesCommandFactory(
|
||||||
|
s_desktopTestFramework,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
null,
|
||||||
|
testInstance.TestRoot);
|
||||||
|
|
||||||
|
var command = factory.Create("dotnet-desktop-and-portable", null);
|
||||||
|
|
||||||
|
command.CommandName.Should().Contain(Path.Combine(testInstance.TestRoot, "bin", configuration));
|
||||||
|
Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
|
||||||
|
}
|
||||||
|
|
||||||
[WindowsOnlyFact]
|
[WindowsOnlyFact]
|
||||||
public void It_resolves_desktop_apps_when_configuration_is_Debug()
|
public void It_resolves_desktop_apps_when_configuration_is_Debug()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue