dotnet-installer/src/Microsoft.DotNet.ProjectModel/OutputPathsCalculator.cs
Andrew Stanton-Nurse 7cc90d9ad1 Update dotnet-build to produce portable layout
dotnet-build will produce a deps file for portable builds, and will now
create "runnable" outputs for RID-less targets

the outputs won't actually be runnable today because we need corehost
changes and to generate a deps.json file for corehost to use.
2016-03-08 11:46:15 -08:00

81 lines
No EOL
3 KiB
C#

// 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.IO;
using Microsoft.DotNet.ProjectModel.Utilities;
using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel
{
public class OutputPathsCalculator
{
private const string ObjDirectoryName = "obj";
private const string BinDirectoryName = "bin";
public static OutputPaths GetOutputPaths(
Project project,
NuGetFramework framework,
string runtimeIdentifier,
string configuration,
string solutionRootPath,
string buildBasePath,
string outputPath)
{
string resolvedBuildBasePath;
if (string.IsNullOrEmpty(buildBasePath))
{
resolvedBuildBasePath = project.ProjectDirectory;
}
else
{
if (string.IsNullOrEmpty(solutionRootPath))
{
resolvedBuildBasePath = Path.Combine(buildBasePath, project.Name);
}
else
{
resolvedBuildBasePath = project.ProjectDirectory.Replace(solutionRootPath, buildBasePath);
}
}
var compilationOutputPath = PathUtility.EnsureTrailingSlash(Path.Combine(resolvedBuildBasePath,
BinDirectoryName,
configuration,
framework.GetShortFolderName()));
string runtimeOutputPath = null;
if (string.IsNullOrEmpty(outputPath))
{
if (!string.IsNullOrEmpty(runtimeIdentifier))
{
runtimeOutputPath = PathUtility.EnsureTrailingSlash(Path.Combine(compilationOutputPath, runtimeIdentifier));
}
else
{
// "Runtime" assets (i.e. the deps file) will be dropped to the compilation output path, because
// we are building a RID-less target.
runtimeOutputPath = compilationOutputPath;
}
}
else
{
runtimeOutputPath = PathUtility.EnsureTrailingSlash(Path.GetFullPath(outputPath));
}
var intermediateOutputPath = PathUtility.EnsureTrailingSlash(Path.Combine(
resolvedBuildBasePath,
ObjDirectoryName,
configuration,
framework.GetTwoDigitShortFolderName()));
var compilationFiles = new CompilationOutputFiles(compilationOutputPath, project, configuration, framework);
RuntimeOutputFiles runtimeFiles = null;
if (runtimeOutputPath != null)
{
runtimeFiles = new RuntimeOutputFiles(runtimeOutputPath, project, configuration, framework);
}
return new OutputPaths(intermediateOutputPath, compilationOutputPath, runtimeOutputPath, compilationFiles, runtimeFiles);
}
}
}