Skip to content

Commit 7b97ebc

Browse files
committed
fix(manifest): fail closed when a dotnet design-time build fails
A failed design-time build now reports a blocking failure for the project and framework instead of only marking the sidecar entry, so --reach does not proceed with compiler inputs missing generated sources, references and analyzers. --ignore-unresolved keeps the evaluated fallback.
1 parent dac1832 commit 7b97ebc

6 files changed

Lines changed: 29 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,8 @@ private void EmitPaths(ProjectInfo info, Project project, List<string> framework
580580
// WPF's, which generates the XAML code-behind sources.
581581
private const string MarkupCompilationTarget = "DesignTimeMarkupCompilation";
582582

583-
// As the compiler task receives it; on a failed design-time build, the
584-
// evaluated values and the build's first error.
583+
// As the compiler task receives it; a failed design-time build fails the
584+
// run, and leaves the evaluated values for --ignore-unresolved.
585585
private void EmitBuild(ProjectInfo info, Project project, string? innerFramework, string config) {
586586
var props = new Dictionary<string, string>(project.GlobalProperties, StringComparer.OrdinalIgnoreCase);
587587
if (innerFramework != null) props["TargetFramework"] = innerFramework;
@@ -590,7 +590,7 @@ private void EmitBuild(ProjectInfo info, Project project, string? innerFramework
590590
var error = DesignTimeBuild(project, props, out compiled);
591591
if (error != null) {
592592
_records.ProjectInfo(info.Key, config, "BuildError", error);
593-
Log($"{info.Key} {config}: design-time build failed: {error}");
593+
Fail(info.Key, $"the design-time build failed: {error}", config, info.Key);
594594
}
595595
}
596596
var instance = compiled;

‎src/commands/manifest/scripts/resolution-report-nuget.mts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function classifyNugetFailure(detail: string): FailureCategory {
3434
code ||
3535
t.startsWith('could not evaluate') ||
3636
t.startsWith('could not read') ||
37+
t.startsWith('the design-time build failed') ||
3738
t.includes('share an intermediate output directory') ||
3839
t.startsWith('project.json projects are not supported')
3940
) {

‎src/commands/manifest/scripts/resolution-report-nuget.test.mts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ describe('classifyNugetFailure', () => {
3737
'could not evaluate the project: The imported project "x.props" was not found.',
3838
'config-problem',
3939
],
40+
[
41+
'the design-time build failed: MSB3644: The reference assemblies for .NETFramework,Version=v4.8 were not found.',
42+
'config-problem',
43+
],
4044
[
4145
'obj/project.assets.json belongs to B.csproj: the projects share an intermediate output directory, so restore output cannot be attributed',
4246
'config-problem',

‎src/commands/manifest/scripts/test/dotnet-compat/assert-facts.py‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ def records(name):
140140
return rows
141141

142142

143+
# Some SDKs' MSBuild finds no .NET Framework reference assemblies off Windows,
144+
# which fails the legacy project's design-time build there, as its compile would.
145+
def package_failures(rows):
146+
return [r for r in rows if r[0] == 'failure' and not r[2].startswith('the design-time build failed: MSB3644')]
147+
148+
143149
def info_rows(rows, project, name, config=None):
144150
return [r for r in rows if r[0] == 'projectInfo' and r[1] == project and r[3] == name and config in (None, r[2])]
145151

@@ -171,6 +177,10 @@ def records_phase():
171177
analyzers = {r[4] for r in info_rows(basic, 'src/Lib/Lib.csproj', 'Analyzer', 'net6.0')}
172178
check(any('demo.ext.analyzer' in p.lower() for p in analyzers), f'analyzers {analyzers}')
173179

180+
designtime = records('designtime.tsv')
181+
failed = [r for r in designtime if r[0] == 'failure' and 'the design-time build failed' in r[2]]
182+
check(len(failed) == 1 and 'generated sources unavailable' in failed[0][2], f'design-time failure {failed}')
183+
174184
langs = records('langs.tsv')
175185
vb = {r[4] for r in info_rows(langs, 'Vb.vbproj', 'DefineConstant')}
176186
check({'DEBUG=-1', 'TRACE=-1'} <= vb, f'VB compiler constants {vb}')
@@ -181,10 +191,10 @@ def records_phase():
181191
missing = records('pc-missing.tsv')
182192
unfetched = {r[2] for r in missing if r[0] == 'unfetched'}
183193
check(unfetched == {'demo.ext.tool:1.0.0', 'demo.ext.shared:1.0.0'}, f'unfetched {unfetched}')
184-
check(sum(r[0] == 'failure' for r in missing) == 2, 'missing packages.config assemblies fail')
194+
check(len(package_failures(missing)) == 2, 'missing packages.config assemblies fail')
185195

186196
present = records('pc-present.tsv')
187-
check(not any(r[0] in ('failure', 'unfetched') for r in present), 'installed packages.config resolves')
197+
check(not package_failures(present) and not any(r[0] == 'unfetched' for r in present), 'installed packages.config resolves')
188198
legacy_roots = {(r[3], r[5], r[7]) for r in present if r[0] == 'root' and r[2] == 'Legacy/Legacy.csproj'}
189199
check(legacy_roots == {('net48', 'net48', 'net48')}, f'Legacy roots (config, framework, alias) {legacy_roots}')
190200
present_files = {r[2] for r in present if r[0] == 'file'}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup><TargetFramework>net6.0</TargetFramework></PropertyGroup>
3+
<ItemGroup><PackageReference Include="Demo.Ext.Tool" Version="1.0.0" /></ItemGroup>
4+
<!-- Restores, but its design-time build fails. -->
5+
<Target Name="FailBeforeCompile" BeforeTargets="CoreCompile">
6+
<Error Text="generated sources unavailable" />
7+
</Target>
8+
</Project>

‎src/commands/manifest/scripts/test/dotnet-compat/smoke-test.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ records() {
115115
}
116116
records "$WORK/basic/Basic.sln" "$WORK/basic.tsv"
117117
records "$WORK/langs/Vb/Vb.vbproj" "$WORK/langs.tsv"
118+
records "$WORK/failures/designtime/DesignTime.csproj" "$WORK/designtime.tsv"
118119
records "$WORK/packages-config/Mixed.sln" "$WORK/pc-missing.tsv"
119120
# What `nuget restore` lays out for packages.config: <Id>.<Version as written>.
120121
python3 - "$WORK" <<'PY'

0 commit comments

Comments
 (0)