dotnet-installer/src/Microsoft.DotNet.Compiler.Common/ProjectContextExtensions.cs

57 lines
2.4 KiB
C#
Raw Normal View History

// 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.
2016-03-08 16:46:50 -08:00
using System;
using System.Collections.Generic;
2016-03-08 16:46:50 -08:00
using System.IO;
using System.Linq;
using Microsoft.DotNet.ProjectModel;
using NuGet.Frameworks;
namespace Microsoft.DotNet.Cli.Compiler.Common
{
public static class ProjectContextExtensions
{
public static string ProjectName(this ProjectContext context) => context.RootProject.Identity.Name;
2016-02-03 10:57:25 -08:00
public static string GetDisplayName(this ProjectContext context) => $"{context.RootProject.Identity.Name} ({context.TargetFramework})";
public static CommonCompilerOptions GetLanguageSpecificCompilerOptions(this ProjectContext context, NuGetFramework framework, string configurationName)
{
var baseOption = context.ProjectFile.GetCompilerOptions(framework, configurationName);
IReadOnlyList<string> defaultSuppresses;
var compilerName = context.ProjectFile.CompilerName ?? "csc";
if (DefaultCompilerWarningSuppresses.Suppresses.TryGetValue(compilerName, out defaultSuppresses))
{
baseOption.SuppressWarnings = (baseOption.SuppressWarnings ?? Enumerable.Empty<string>()).Concat(defaultSuppresses).Distinct();
}
return baseOption;
}
2016-03-08 16:46:50 -08:00
// used in incremental compilation for the key file
public static CommonCompilerOptions ResolveCompilationOptions(this ProjectContext context, string configuration)
{
var compilationOptions = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration);
// Path to strong naming key in environment variable overrides path in project.json
var environmentKeyFile = Environment.GetEnvironmentVariable(EnvironmentNames.StrongNameKeyFile);
if (!string.IsNullOrWhiteSpace(environmentKeyFile))
{
compilationOptions.KeyFile = environmentKeyFile;
}
else if (!string.IsNullOrWhiteSpace(compilationOptions.KeyFile))
{
// Resolve full path to key file
compilationOptions.KeyFile =
Path.GetFullPath(Path.Combine(context.ProjectFile.ProjectDirectory, compilationOptions.KeyFile));
}
return compilationOptions;
}
}
}