2016-01-20 15:41:46 -08:00
|
|
|
|
// 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;
|
2016-01-26 06:39:13 -08:00
|
|
|
|
using System.Runtime.InteropServices;
|
2016-01-20 15:41:46 -08:00
|
|
|
|
using NuGet.Frameworks;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.ProjectModel
|
|
|
|
|
{
|
|
|
|
|
public class OutputPathCalculator
|
|
|
|
|
{
|
2016-01-21 15:01:21 -08:00
|
|
|
|
private const string ObjDirectoryName = "obj";
|
|
|
|
|
|
2016-01-26 06:39:13 -08:00
|
|
|
|
private readonly Project _project;
|
|
|
|
|
private readonly NuGetFramework _framework;
|
|
|
|
|
|
|
|
|
|
private readonly string _runtimeIdentifier;
|
2016-01-20 15:41:46 -08:00
|
|
|
|
|
2016-01-21 15:01:21 -08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Unaltered output path. Either what is passed in in the constructor, or the project directory.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string BaseOutputPath { get; }
|
|
|
|
|
|
|
|
|
|
public string BaseCompilationOutputPath { get; }
|
2016-01-20 15:41:46 -08:00
|
|
|
|
|
|
|
|
|
public OutputPathCalculator(
|
2016-01-26 06:39:13 -08:00
|
|
|
|
Project project,
|
|
|
|
|
NuGetFramework framework,
|
|
|
|
|
string runtimeIdentifier,
|
2016-01-21 15:01:21 -08:00
|
|
|
|
string baseOutputPath)
|
2016-01-20 15:41:46 -08:00
|
|
|
|
{
|
|
|
|
|
_project = project;
|
2016-01-26 06:39:13 -08:00
|
|
|
|
_framework = framework;
|
|
|
|
|
_runtimeIdentifier = runtimeIdentifier;
|
2016-01-21 15:01:21 -08:00
|
|
|
|
|
|
|
|
|
BaseOutputPath = string.IsNullOrWhiteSpace(baseOutputPath) ? _project.ProjectDirectory : baseOutputPath;
|
|
|
|
|
|
|
|
|
|
BaseCompilationOutputPath = string.IsNullOrWhiteSpace(baseOutputPath)
|
2016-01-20 15:41:46 -08:00
|
|
|
|
? Path.Combine(_project.ProjectDirectory, DirectoryNames.Bin)
|
2016-01-21 15:01:21 -08:00
|
|
|
|
: baseOutputPath;
|
2016-01-20 15:41:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-26 06:39:13 -08:00
|
|
|
|
public string GetOutputDirectoryPath(string buildConfiguration)
|
2016-01-20 15:41:46 -08:00
|
|
|
|
{
|
2016-01-26 06:39:13 -08:00
|
|
|
|
var outDir = Path.Combine(BaseCompilationOutputPath,
|
2016-01-20 15:41:46 -08:00
|
|
|
|
buildConfiguration,
|
2016-01-26 06:39:13 -08:00
|
|
|
|
_framework.GetShortFolderName());
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(_runtimeIdentifier))
|
|
|
|
|
{
|
|
|
|
|
outDir = Path.Combine(outDir, _runtimeIdentifier);
|
|
|
|
|
}
|
2016-01-20 15:41:46 -08:00
|
|
|
|
|
|
|
|
|
return outDir;
|
|
|
|
|
}
|
2016-01-21 15:01:21 -08:00
|
|
|
|
|
2016-01-26 06:39:13 -08:00
|
|
|
|
public string GetIntermediateOutputDirectoryPath(string buildConfiguration, string intermediateOutputValue)
|
2016-01-21 15:01:21 -08:00
|
|
|
|
{
|
|
|
|
|
string intermediateOutputPath;
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(intermediateOutputValue))
|
|
|
|
|
{
|
|
|
|
|
intermediateOutputPath = Path.Combine(
|
|
|
|
|
BaseOutputPath,
|
|
|
|
|
ObjDirectoryName,
|
|
|
|
|
buildConfiguration,
|
2016-01-26 06:39:13 -08:00
|
|
|
|
_framework.GetTwoDigitShortFolderName());
|
2016-01-21 15:01:21 -08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
intermediateOutputPath = intermediateOutputValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return intermediateOutputPath;
|
|
|
|
|
}
|
2016-01-26 06:39:13 -08:00
|
|
|
|
|
|
|
|
|
public string GetAssemblyPath(string buildConfiguration)
|
|
|
|
|
{
|
|
|
|
|
var compilationOptions = _project.GetCompilerOptions(_framework, buildConfiguration);
|
|
|
|
|
var outputExtension = FileNameSuffixes.DotNet.DynamicLib;
|
|
|
|
|
|
|
|
|
|
if (_framework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault())
|
|
|
|
|
{
|
|
|
|
|
outputExtension = FileNameSuffixes.DotNet.Exe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Path.Combine(
|
|
|
|
|
GetOutputDirectoryPath(buildConfiguration),
|
|
|
|
|
_project.Name + outputExtension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetExecutablePath(string buildConfiguration)
|
|
|
|
|
{
|
|
|
|
|
var extension = FileNameSuffixes.CurrentPlatform.Exe;
|
|
|
|
|
|
|
|
|
|
// This is the check for mono, if we're not on windows and producing outputs for
|
|
|
|
|
// the desktop framework then it's an exe
|
|
|
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && _framework.IsDesktop())
|
|
|
|
|
{
|
|
|
|
|
extension = FileNameSuffixes.DotNet.Exe;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Path.Combine(
|
|
|
|
|
GetOutputDirectoryPath(buildConfiguration),
|
|
|
|
|
_project.Name + extension);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetPdbPath(string buildConfiguration)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(
|
|
|
|
|
GetOutputDirectoryPath(buildConfiguration),
|
|
|
|
|
_project.Name + FileNameSuffixes.DotNet.ProgramDatabase);
|
|
|
|
|
}
|
2016-01-20 15:41:46 -08:00
|
|
|
|
}
|
|
|
|
|
}
|