This repository has been archived by the owner on Apr 20, 2023. It is now read-only.
/
CompilationOutputFiles.cs
104 lines (89 loc) · 3.4 KB
/
CompilationOutputFiles.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
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.ProjectModel.Files;
using Microsoft.DotNet.ProjectModel.Resources;
using NuGet.Frameworks;
namespace Microsoft.DotNet.ProjectModel
{
public class CompilationOutputFiles
{
protected readonly Project Project;
protected readonly string Configuration;
protected readonly NuGetFramework Framework;
public CompilationOutputFiles(
string basePath,
Project project,
string configuration,
NuGetFramework framework)
{
BasePath = basePath;
Project = project;
Configuration = configuration;
Framework = framework;
OutputExtension = FileNameSuffixes.DotNet.DynamicLib;
var compilerOptions = Project.GetCompilerOptions(framework, configuration);
if (framework.IsDesktop() && compilerOptions.EmitEntryPoint.GetValueOrDefault())
{
OutputExtension = FileNameSuffixes.DotNet.Exe;
}
}
public string BasePath { get; }
public string Assembly
{
get
{
var compilerOptions = Project.GetCompilerOptions(Framework, Configuration);
return Path.Combine(BasePath, compilerOptions.OutputName + OutputExtension);
}
}
public string PdbPath
{
get
{
return Path.ChangeExtension(Assembly, FileNameSuffixes.CurrentPlatform.ProgramDatabase);
}
}
public string OutputExtension { get; }
public virtual IEnumerable<ResourceFile> Resources()
{
var resourceCultureNames = GetResourceFiles()
.Select(f => ResourceUtility.GetResourceCultureName(f))
.Where(f => !string.IsNullOrEmpty(f))
.Distinct();
foreach (var resourceCultureName in resourceCultureNames)
{
yield return new ResourceFile(
Path.Combine(
BasePath, resourceCultureName, Project.Name + ".resources" + FileNameSuffixes.DotNet.DynamicLib),
resourceCultureName);
}
}
public virtual IEnumerable<string> All()
{
yield return Assembly;
yield return PdbPath;
var compilerOptions = Project.GetCompilerOptions(Framework, Configuration);
if (compilerOptions.GenerateXmlDocumentation == true)
{
yield return Path.ChangeExtension(Assembly, "xml");
}
foreach (var resource in Resources())
{
yield return resource.Path;
}
}
private IEnumerable<string> GetResourceFiles()
{
var compilerOptions = Project.GetCompilerOptions(Framework, Configuration);
if (compilerOptions.EmbedInclude == null)
{
return Project.Files.ResourceFiles.Keys;
}
var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilerOptions.EmbedInclude, "/", diagnostics: null);
return includeFiles.Select(f => f.SourcePath);
}
}
}