Skip to content

Commit f15b23b

Browse files
committed
Make SCC properties dependent on packing
The source control provider is not queried normally from within regular IDE/DesignTime builds, so we get false positives.
1 parent 3b1936b commit f15b23b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/CodeAnalysis/MetadataAnalyzer.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,35 +201,35 @@ public override void Initialize(AnalysisContext context)
201201
if (options.TryGetValue("build_property.SourceControlInformationFeatureSupported", out var sccSupported) &&
202202
"true".Equals(sccSupported, StringComparison.OrdinalIgnoreCase))
203203
{
204-
string? repoCommit = default;
205-
206-
if (!options.TryGetValue("build_property.RepositoryCommit", out repoCommit) ||
207-
string.IsNullOrWhiteSpace(repoCommit))
208-
{
209-
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingRepositoryCommit, null));
210-
repoCommit = default;
211-
}
212204

213205
if (isPacking)
214206
{
207+
string? repoCommit = default;
208+
209+
if (!options.TryGetValue("build_property.RepositoryCommit", out repoCommit) ||
210+
string.IsNullOrWhiteSpace(repoCommit))
211+
{
212+
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingRepositoryCommit, null));
213+
repoCommit = default;
214+
}
215+
215216
if (!sourceLinkEnabled)
216217
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingSourceLink, null));
217218
// When packing, suggest reproducible builds by embedding untrack sources
218219
else if (!options.TryGetValue("build_property.EmbedUntrackedSources", out var embedUntracked) ||
219220
!"true".Equals(embedUntracked, StringComparison.OrdinalIgnoreCase))
220221
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingSourceEmbed, null));
221-
}
222-
}
223-
224-
if (!options.TryGetValue("build_property.RepositoryUrl", out var repoUrl) ||
225-
string.IsNullOrWhiteSpace(repoUrl))
226-
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingRepositoryUrl, null));
227222

228-
if (!options.TryGetValue("build_property.PackageProjectUrl", out var projectUrl) ||
229-
string.IsNullOrWhiteSpace(projectUrl) ||
230-
projectUrl == repoUrl)
231-
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingProjectUrl, null, repoUrl));
223+
if (!options.TryGetValue("build_property.RepositoryUrl", out var repoUrl) ||
224+
string.IsNullOrWhiteSpace(repoUrl))
225+
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingRepositoryUrl, null));
232226

227+
if (!options.TryGetValue("build_property.PackageProjectUrl", out var projectUrl) ||
228+
string.IsNullOrWhiteSpace(projectUrl) ||
229+
projectUrl == repoUrl)
230+
ctx.ReportDiagnostic(Diagnostic.Create(Descriptors.MissingProjectUrl, null, repoUrl));
231+
}
232+
}
233233
});
234234
}
235235
}

0 commit comments

Comments
 (0)