This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathProject.cs
155 lines (110 loc) · 5.23 KB
/
Project.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// 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;
using System.Collections.Generic;
using System.IO;
using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.DotNet.ProjectModel.Graph;
using NuGet.Frameworks;
using NuGet.Versioning;
namespace Microsoft.DotNet.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>();
internal Dictionary<string, CommonCompilerOptions> _compilerOptionsByConfiguration = new Dictionary<string, CommonCompilerOptions>(StringComparer.OrdinalIgnoreCase);
internal CommonCompilerOptions _defaultCompilerOptions;
internal TargetFrameworkInformation _defaultTargetFrameworkConfiguration;
public Project()
{
}
public string ProjectFilePath { get; set; }
public string ProjectDirectory
{
get
{
return Path.GetDirectoryName(ProjectFilePath);
}
}
public AnalyzerOptions AnalyzerOptions { get; set; }
public string Name { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public string Copyright { get; set; }
public string Language { get; set; }
public string[] Authors { get; set; }
public bool EmbedInteropTypes { get; set; }
public NuGetVersion Version { get; set; }
public Version AssemblyFileVersion { get; set; }
public IList<LibraryRange> Dependencies { get; set; }
public List<LibraryRange> Tools { get; set; }
public string EntryPoint { get; set; }
public string TestRunner { get; set; }
public ProjectFilesCollection Files { get; set; }
public PackOptions PackOptions { get; set; }
public bool Serviceable { get; set; }
public RuntimeOptions RuntimeOptions { 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 string RawRuntimeOptions { get; set; }
public IncludeContext PublishOptions { get; set; }
public List<DiagnosticMessage> Diagnostics { get; } = new List<DiagnosticMessage>();
public bool IsTestProject => !string.IsNullOrEmpty(TestRunner);
public IEnumerable<TargetFrameworkInformation> GetTargetFrameworks()
{
return _targetFrameworks.Values;
}
public IEnumerable<string> GetConfigurations()
{
return _compilerOptionsByConfiguration.Keys;
}
public CommonCompilerOptions GetCompilerOptions(NuGetFramework targetFramework, 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
var compilerOptions = CommonCompilerOptions.Combine(rootOptions, configurationOptions, targetFrameworkOptions);
if (compilerOptions.OutputName == null)
{
compilerOptions.OutputName = Name;
}
return compilerOptions;
}
public TargetFrameworkInformation GetTargetFramework(NuGetFramework targetFramework)
{
TargetFrameworkInformation targetFrameworkInfo = null;
if (targetFramework != null && _targetFrameworks.TryGetValue(targetFramework, out targetFrameworkInfo))
{
return targetFrameworkInfo;
}
return targetFrameworkInfo ?? _defaultTargetFrameworkConfiguration;
}
public bool HasRuntimeOutput(string configuration)
{
var compilerOptions = GetCompilerOptions(targetFramework: null, configurationName: configuration);
// TODO: Make this opt in via another mechanism
return compilerOptions.EmitEntryPoint.GetValueOrDefault() || IsTestProject;
}
private CommonCompilerOptions GetCompilerOptions()
{
return _defaultCompilerOptions;
}
private CommonCompilerOptions GetCompilerOptions(string configurationName)
{
CommonCompilerOptions options;
if (_compilerOptionsByConfiguration.TryGetValue(configurationName, out options))
{
return options;
}
return null;
}
private CommonCompilerOptions GetCompilerOptions(NuGetFramework frameworkName)
{
return GetTargetFramework(frameworkName)?.CompilerOptions;
}
}
}