Skip to content

Commit f708e85

Browse files
[tests] Clear ResolvedCodeAnalysisRuleSet to fix CoreCompile incrementality (#10900)
CI Guardian SDL analysis (MergeGuardianDotnetAnalyzersRuleSets) regenerates a merged .ruleset file on every build with a new timestamp. Since is in CoreCompile's Inputs, this causes CoreCompile to re-run even when no source files changed, cascading through ILLink -> _GenerateJavaStubs -> _Sign and breaking incrementality tests: - BasicApplicationRepetitiveReleaseBuild - CheckTimestamps - GenerateJavaStubsAndAssembly * Move _ClearResolvedCodeAnalysisRuleSet to XamarinAndroidProject base class Unify the Directory.Build.targets logic so the _ClearResolvedCodeAnalysisRuleSet target is defined once in XamarinAndroidProject (base class) rather than duplicated in each derived project type. This fixes the BindingLibraryIncremental test which uses XamarinAndroidBindingProject (inherits directly from XamarinAndroidProject, not XamarinAndroidApplicationProject). Added ExtraDirectoryBuildTargetsContent virtual property so XamarinAndroidApplicationProject can still inject VectorDrawable workaround. Also updated copilot-instructions.md to prefer raw string literals.
1 parent 720d838 commit f708e85

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ C# code uses tabs (not spaces) and Mono style (`.editorconfig`):
142142
- Preserve existing formatting and comments
143143
- Space before `(` and `[`: `Foo ()`, `array [0]`
144144
- Use `""` not `string.Empty`, `[]` not `Array.Empty<T>()`
145+
- Prefer C# raw string literals (`"""`) for multi-line strings instead of `@""` with escaped quotes
145146
- Minimal diffs - don't leave random empty lines
146147
- Do NOT use `#region` or `#endregion`
147148

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidApplicationProject.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ namespace Xamarin.ProjectTools
2929
/// <seealso cref="XamarinAndroidBindingProject"/>
3030
public class XamarinAndroidApplicationProject : XamarinAndroidCommonProject
3131
{
32+
// Workaround for AndroidX, see: https://github.com/xamarin/AndroidSupportComponents/pull/239
33+
protected override string ExtraDirectoryBuildTargetsContent => """
34+
<PropertyGroup>
35+
<VectorDrawableCheckBuildToolsVersionTaskBeforeTargets />
36+
</PropertyGroup>
37+
""";
38+
3239
const string default_strings_xml = @"<?xml version=""1.0"" encoding=""utf-8""?>
3340
<resources>
3441
<string name=""hello"">Hello World, Click Me!</string>
@@ -74,16 +81,6 @@ public XamarinAndroidApplicationProject (string debugConfigurationName = "Debug"
7481
SetProperty ("_FastDeploymentDiagnosticLogging", "True");
7582
SupportedOSPlatformVersion = "21.0";
7683

77-
// Workaround for AndroidX, see: https://github.com/xamarin/AndroidSupportComponents/pull/239
78-
Imports.Add (new Import (() => "Directory.Build.targets") {
79-
TextContent = () =>
80-
@"<Project>
81-
<PropertyGroup>
82-
<VectorDrawableCheckBuildToolsVersionTaskBeforeTargets />
83-
</PropertyGroup>
84-
</Project>"
85-
});
86-
8784
AndroidManifest = default_android_manifest;
8885
LayoutMain = default_layout_main;
8986
StringsXml = default_strings_xml;

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Android/XamarinAndroidProject.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ namespace Xamarin.ProjectTools
2222
/// <seealso cref="XamarinAndroidProjectLanguage"/>
2323
public abstract class XamarinAndroidProject : DotNetXamarinProject
2424
{
25+
/// <summary>
26+
/// Override to provide additional MSBuild XML content inside the auto-generated Directory.Build.targets file.
27+
/// The returned string is inserted as-is inside the root &lt;Project&gt; element, before the
28+
/// <c>_ClearResolvedCodeAnalysisRuleSet</c> target.
29+
/// </summary>
30+
protected virtual string ExtraDirectoryBuildTargetsContent => "";
31+
2532
/// <summary>
2633
/// Initializes a new instance of the XamarinAndroidProject class with the specified configuration names.
2734
/// Sets the default language to C# and output type to Library.
@@ -35,6 +42,24 @@ protected XamarinAndroidProject (string debugConfigurationName = "Debug", string
3542
{
3643
Language = XamarinAndroidProjectLanguage.CSharp;
3744
SetProperty (KnownProperties.OutputType, "Library");
45+
46+
// Prevent CI Guardian SDL analysis from breaking CoreCompile incrementality.
47+
// Guardian's MergeGuardianDotnetAnalyzersRuleSets target regenerates a merged
48+
// ruleset file on every build (new timestamp), which is in CoreCompile's Inputs
49+
// via $(ResolvedCodeAnalysisRuleSet). Clearing this property ensures CoreCompile
50+
// is properly incremental when source files haven't changed.
51+
Imports.Add (new Import (() => "Directory.Build.targets") {
52+
TextContent = () => $"""
53+
<Project>
54+
{ExtraDirectoryBuildTargetsContent}
55+
<Target Name="_ClearResolvedCodeAnalysisRuleSet" BeforeTargets="CoreCompile" AfterTargets="ResolveCodeAnalysisRuleSet;MergeGuardianDotnetAnalyzersRuleSets">
56+
<PropertyGroup>
57+
<ResolvedCodeAnalysisRuleSet />
58+
</PropertyGroup>
59+
</Target>
60+
</Project>
61+
""",
62+
});
3863
}
3964

4065
/// <summary>

0 commit comments

Comments
 (0)