2015-10-13 14:31:29 -07:00
|
|
|
// Copyright (c) .NET Foundation. All rights reserved.
|
|
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.IO;
|
2015-10-17 08:55:06 -07:00
|
|
|
using Microsoft.Extensions.ProjectModel.Files;
|
2015-10-13 14:31:29 -07:00
|
|
|
using Microsoft.Extensions.ProjectModel.Graph;
|
|
|
|
using NuGet.Frameworks;
|
|
|
|
using NuGet.Versioning;
|
|
|
|
|
|
|
|
namespace Microsoft.Extensions.ProjectModel
|
|
|
|
{
|
|
|
|
public class Project
|
|
|
|
{
|
|
|
|
public static readonly string FileName = "project.json";
|
|
|
|
|
|
|
|
// REVIEW: It's kinda hacky making these internal but the reader needs to set them
|
|
|
|
internal Dictionary<NuGetFramework, TargetFrameworkInformation> _targetFrameworks = new Dictionary<NuGetFramework, TargetFrameworkInformation>();
|
2015-10-20 13:27:56 -07:00
|
|
|
internal Dictionary<string, CommonCompilerOptions> _compilerOptionsByConfiguration = new Dictionary<string, CommonCompilerOptions>(StringComparer.OrdinalIgnoreCase);
|
2015-10-13 14:31:29 -07:00
|
|
|
|
2015-10-20 13:27:56 -07:00
|
|
|
internal CommonCompilerOptions _defaultCompilerOptions;
|
2015-10-13 14:31:29 -07:00
|
|
|
internal TargetFrameworkInformation _defaultTargetFrameworkConfiguration;
|
|
|
|
|
|
|
|
public Project()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ProjectFilePath { get; set; }
|
|
|
|
|
|
|
|
public string ProjectDirectory
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return Path.GetDirectoryName(ProjectFilePath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
|
|
|
public string Copyright { get; set; }
|
|
|
|
|
|
|
|
public string Summary { get; set; }
|
|
|
|
|
|
|
|
public string Language { get; set; }
|
|
|
|
|
|
|
|
public string ReleaseNotes { get; set; }
|
|
|
|
|
|
|
|
public string[] Authors { get; set; }
|
|
|
|
|
|
|
|
public string[] Owners { get; set; }
|
|
|
|
|
|
|
|
public bool EmbedInteropTypes { get; set; }
|
|
|
|
|
|
|
|
public NuGetVersion Version { get; set; }
|
|
|
|
|
|
|
|
public Version AssemblyFileVersion { get; set; }
|
|
|
|
|
|
|
|
public IList<LibraryRange> Dependencies { get; set; }
|
|
|
|
|
|
|
|
public string EntryPoint { get; set; }
|
|
|
|
|
|
|
|
public string ProjectUrl { get; set; }
|
|
|
|
|
|
|
|
public string LicenseUrl { get; set; }
|
|
|
|
|
|
|
|
public string IconUrl { get; set; }
|
|
|
|
|
|
|
|
public bool RequireLicenseAcceptance { get; set; }
|
|
|
|
|
|
|
|
public string[] Tags { get; set; }
|
|
|
|
|
2015-10-23 15:21:49 -07:00
|
|
|
public string CompilerName { get; set; }
|
|
|
|
|
2015-10-13 14:31:29 -07:00
|
|
|
public ProjectFilesCollection Files { get; set; }
|
|
|
|
|
|
|
|
public IDictionary<string, string> Commands { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
public IDictionary<string, IEnumerable<string>> Scripts { get; } = new Dictionary<string, IEnumerable<string>>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
public IEnumerable<TargetFrameworkInformation> GetTargetFrameworks()
|
|
|
|
{
|
|
|
|
return _targetFrameworks.Values;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEnumerable<string> GetConfigurations()
|
|
|
|
{
|
|
|
|
return _compilerOptionsByConfiguration.Keys;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:27:56 -07:00
|
|
|
public CommonCompilerOptions GetCompilerOptions(NuGetFramework targetFramework,
|
2015-10-13 14:31:29 -07:00
|
|
|
string configurationName)
|
|
|
|
{
|
|
|
|
// Get all project options and combine them
|
|
|
|
var rootOptions = GetCompilerOptions();
|
|
|
|
var configurationOptions = configurationName != null ? GetCompilerOptions(configurationName) : null;
|
|
|
|
var targetFrameworkOptions = targetFramework != null ? GetCompilerOptions(targetFramework) : null;
|
|
|
|
|
|
|
|
// Combine all of the options
|
2015-10-20 13:27:56 -07:00
|
|
|
return CommonCompilerOptions.Combine(rootOptions, configurationOptions, targetFrameworkOptions);
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public TargetFrameworkInformation GetTargetFramework(NuGetFramework targetFramework)
|
|
|
|
{
|
|
|
|
TargetFrameworkInformation targetFrameworkInfo = null;
|
|
|
|
if (targetFramework != null && _targetFrameworks.TryGetValue(targetFramework, out targetFrameworkInfo))
|
|
|
|
{
|
|
|
|
return targetFrameworkInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
return targetFrameworkInfo ?? _defaultTargetFrameworkConfiguration;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:27:56 -07:00
|
|
|
private CommonCompilerOptions GetCompilerOptions()
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
|
|
|
return _defaultCompilerOptions;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:27:56 -07:00
|
|
|
private CommonCompilerOptions GetCompilerOptions(string configurationName)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2015-10-20 13:27:56 -07:00
|
|
|
CommonCompilerOptions options;
|
2015-10-13 14:31:29 -07:00
|
|
|
if (_compilerOptionsByConfiguration.TryGetValue(configurationName, out options))
|
|
|
|
{
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-10-20 13:27:56 -07:00
|
|
|
private CommonCompilerOptions GetCompilerOptions(NuGetFramework frameworkName)
|
2015-10-13 14:31:29 -07:00
|
|
|
{
|
2015-10-17 08:36:22 -07:00
|
|
|
return GetTargetFramework(frameworkName)?.CompilerOptions;
|
2015-10-13 14:31:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|