Skip to content

Commit 6fc28cb

Browse files
committed
fix(manifest): dotnet compiler inputs from a design-time build, build-delivered prod packages
- Read each build's compiler inputs from a design-time build in the shape of Roslyn's MSBuildWorkspace, in one build session: sources in compile order with generated ones, every reference including framework reference packs, analyzers, nullable, and VB's FinalDefineConstants. A failed build falls back to the evaluated values plus the SDK's implicit symbols and records the first error. - A package with active build files and no nuspec developmentDependency declaration counts as prod: build targets can copy files into the output. - Resolve the entry's symlinks once, so restore's paths through a symlinked directory no longer read as a project sharing another's obj/. - --exclude-base anchors --exclude-paths outside the build root.
1 parent 61d2036 commit 6fc28cb

11 files changed

Lines changed: 322 additions & 64 deletions

File tree

‎src/commands/manifest/scripts/assemble.mts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,9 @@ function buildFrameworks(
544544
targetFrameworkMoniker: one('TargetFrameworkMoniker'),
545545
language: one('Language'),
546546
langVersion: one('LangVersion'),
547+
nullable: one('Nullable'),
547548
assemblyName: one('AssemblyName'),
549+
buildError: one('BuildError'),
548550
frameworkReferences: sortedUnique(
549551
build?.info.get('FrameworkReference') ?? [],
550552
),
@@ -554,7 +556,10 @@ function buildFrameworks(
554556
...(u.alias ? { alias: u.alias } : {}),
555557
...(u.static ? { static: true as const } : {}),
556558
})),
557-
sources: sortedUnique(build?.sources ?? []).filter(exists),
559+
// In compiler order, which F# depends on.
560+
sources: [...new Set(build?.sources)].filter(exists),
561+
references: [...new Set(build?.info.get('Reference'))].filter(exists),
562+
analyzers: [...new Set(build?.info.get('Analyzer'))].filter(exists),
558563
targets: sortedUnique(build?.targets ?? []).filter(exists),
559564
dependencies: [],
560565
classpath: [],

‎src/commands/manifest/scripts/assemble.test.mts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,11 +659,17 @@ describe('dotnet records → per-framework sidecar', () => {
659659
'meta\tdotnet\t8.0.414\t',
660660
'project\tLib.csproj\t\tLib\t1.0.0\t.',
661661
'projectSrc\tLib.csproj\t/abs/L.cs\tnet8.0',
662+
'projectSrc\tLib.csproj\t/abs/obj/Lib.AssemblyInfo.cs\tnet8.0',
662663
'projectSrc\tLib.csproj\t/abs/Legacy.cs\tnetstandard2.0',
664+
'projectInfo\tLib.csproj\tnetstandard2.0\tBuildError\tMSB3644: reference assemblies not found',
663665
'projectTgt\tLib.csproj\t/abs/bin/net8.0/Lib.dll\tnet8.0',
664666
'projectInfo\tLib.csproj\tnet8.0\tTargetFrameworkMoniker\t.NETCoreApp,Version=v8.0',
665667
'projectInfo\tLib.csproj\tnet8.0\tDefineConstant\tNET8_0_OR_GREATER',
666668
'projectInfo\tLib.csproj\tnet8.0\tFrameworkReference\tMicrosoft.NETCore.App',
669+
'projectInfo\tLib.csproj\tnet8.0\tNullable\tenable',
670+
'projectInfo\tLib.csproj\tnet8.0\tReference\t/packs/ref/net8.0/System.Runtime.dll',
671+
'projectInfo\tLib.csproj\tnet8.0\tReference\t/pkgs/x/ref/net8.0/X.dll',
672+
'projectInfo\tLib.csproj\tnet8.0\tAnalyzer\t/packs/analyzers/Gen.dll',
667673
'projectUsing\tLib.csproj\tnet8.0\tSystem.Linq\t\t0',
668674
'projectUsing\tLib.csproj\tnet8.0\tSystem.Math\t\t1',
669675
'root\ta\tLib.csproj\tnet8.0\t0\tnet8.0\t\tnet8.0',
@@ -699,21 +705,31 @@ describe('dotnet records → per-framework sidecar', () => {
699705
targetFrameworkMoniker: '.NETCoreApp,Version=v8.0',
700706
language: undefined,
701707
langVersion: undefined,
708+
nullable: 'enable',
702709
assemblyName: undefined,
710+
buildError: undefined,
703711
frameworkReferences: ['Microsoft.NETCore.App'],
704712
defineConstants: ['NET8_0_OR_GREATER'],
705713
usings: [
706714
{ namespace: 'System.Linq' },
707715
{ namespace: 'System.Math', static: true },
708716
],
709-
sources: ['/abs/L.cs'],
717+
// Compiler order, not sorted.
718+
sources: ['/abs/L.cs', '/abs/obj/Lib.AssemblyInfo.cs'],
719+
references: [
720+
'/packs/ref/net8.0/System.Runtime.dll',
721+
'/pkgs/x/ref/net8.0/X.dll',
722+
],
723+
analyzers: ['/packs/analyzers/Gen.dll'],
710724
targets: ['/abs/bin/net8.0/Lib.dll'],
711725
dependencies: ['gone:1.0.0', 'x:1.0.0'],
712726
classpath: ['gone:1.0.0', 'x:1.0.0'],
713727
},
714728
expect.objectContaining({
715729
alias: 'netstandard2.0',
730+
buildError: 'MSB3644: reference assemblies not found',
716731
sources: ['/abs/Legacy.cs'],
732+
references: [],
717733
targets: [],
718734
classpath: ['x:1.0.0'],
719735
}),

‎src/commands/manifest/scripts/dotnet-tool/FactsRunner.cs‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ internal sealed partial class Session {
5050
private readonly ToolOptions _opts;
5151
private readonly RecordsWriter _records;
5252
private readonly string _buildRoot;
53+
private readonly string _excludeBase;
5354
private readonly Globs _configs;
5455
private readonly PathExcludes _excludes;
5556
private readonly HashSet<string> _scanned = new(StringComparer.Ordinal);
@@ -61,6 +62,7 @@ public Session(ToolOptions opts, RecordsWriter records) {
6162
_opts = opts;
6263
_records = records;
6364
_buildRoot = Path.GetDirectoryName(opts.EntryPath)!;
65+
_excludeBase = string.IsNullOrEmpty(opts.ExcludeBase) ? _buildRoot : opts.ExcludeBase;
6466
_configs = new Globs(opts.IncludeConfigs, opts.ExcludeConfigs);
6567
_excludes = new PathExcludes(opts.ExcludePaths);
6668
}
@@ -123,6 +125,7 @@ public void Execute() {
123125
}
124126
foreach (var loaded in postRestore.GetLoadedProjects(path).ToList()) postRestore.UnloadProject(loaded);
125127
}
128+
EndDesignTimeBuilds();
126129
ReportRestoreErrors();
127130
}
128131

@@ -137,10 +140,14 @@ private ProjectInfo Register(string path) {
137140
return info;
138141
}
139142

143+
// Relative to --exclude-base when given; a project outside it never matches.
144+
private bool IsExcludedProject(string path) {
145+
var rel = RelTo(_excludeBase, Path.GetDirectoryName(path)!);
146+
return rel != ".." && !rel.StartsWith("../", StringComparison.Ordinal) && _excludes.IsExcluded(rel);
147+
}
148+
140149
// The solution's members its active configuration builds, or the entry
141150
// project itself.
142-
private bool IsExcludedProject(string path) => _excludes.IsExcluded(Rel(Path.GetDirectoryName(path)!));
143-
144151
private List<string>? EntryProjects() {
145152
var entry = _opts.EntryPath;
146153
if (!IsSolution(entry)) return new List<string> { entry };
@@ -308,11 +315,21 @@ private void Log(string message) {
308315
}
309316

310317
// Build-root-relative with `/`, the shape every record path takes.
311-
private string Rel(string path) {
312-
var rel = Path.GetRelativePath(_buildRoot, path).Replace('\\', '/');
318+
private string Rel(string path) => RelTo(_buildRoot, path);
319+
320+
private static string RelTo(string root, string path) {
321+
var rel = Path.GetRelativePath(root, Path.GetFullPath(path)).Replace('\\', '/');
313322
return string.IsNullOrEmpty(rel) ? "." : rel;
314323
}
315324

325+
private static bool SamePath(string a, string b) {
326+
return string.Equals(
327+
RealPaths.Of(a),
328+
RealPaths.Of(b),
329+
OperatingSystem.IsLinux() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase
330+
);
331+
}
332+
316333
private static bool IsSolution(string path) {
317334
var ext = Path.GetExtension(path);
318335
return ext.Equals(".sln", StringComparison.OrdinalIgnoreCase)

‎src/commands/manifest/scripts/dotnet-tool/Patterns.cs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,28 @@ public static void TryDelete(string path) {
108108
}
109109
}
110110
}
111+
112+
// Restore reports some paths through a symlinked directory's target (macOS's
113+
// /var -> /private/var); the last segment keeps the name it was given.
114+
internal static class RealPaths {
115+
private static readonly Dictionary<string, string> Dirs = new(StringComparer.Ordinal);
116+
117+
public static string Of(string path) {
118+
var full = Path.TrimEndingDirectorySeparator(Path.GetFullPath(path));
119+
var dir = Path.GetDirectoryName(full);
120+
return dir == null ? full : Path.Combine(Dir(dir), Path.GetFileName(full));
121+
}
122+
123+
public static string Dir(string dir) {
124+
if (Dirs.TryGetValue(dir, out var known)) return known;
125+
var parent = Path.GetDirectoryName(dir);
126+
var real = parent == null ? dir : Path.Combine(Dir(parent), Path.GetFileName(dir));
127+
try {
128+
if (new DirectoryInfo(real).ResolveLinkTarget(returnFinalTarget: true) is { } target) real = Dir(target.FullName);
129+
} catch (Exception e) when (e is IOException or UnauthorizedAccessException) {
130+
// Unresolvable links stay as written.
131+
}
132+
Dirs[dir] = real;
133+
return real;
134+
}
135+
}

0 commit comments

Comments
 (0)