Skip to content

Commit

Permalink
[tests] don't delete NuGet.config files during MSBuild tests (#4901)
Browse files Browse the repository at this point in the history
Running under .NET 5+, the `AndroidResourceChange` test would always
fail with:

    The target _ResolveLibraryProjectImports should have been skipped.

It turns out our test infrastructure was deleting `NuGet.config` on
incremental builds. This triggers the `Restore` target to do its work
again on every build changing `$(ProjectAssetsFile)`. This is an input
of `_ResolveLibraryProjectImports`:

    <Target Name="_ResolveLibraryProjectImports"
        Inputs="$(ProjectAssetsFile)...

We shouldn't ever delete `NuGet.config` files during MSBuild tests.
This allowed the test to pass, and we can now run it under `dotnet`.

The same was happening for `build.log`, `msbuild.binlog`, and
`process.log`, so I thought it would be good to skip deletion of
`.log` or `.binlog` files.

I also cleaned up the test a little to use `AssertTargetIsSkipped`.
  • Loading branch information
jonathanpeppers authored and jonpryor committed Jul 10, 2020
1 parent 867e79b commit 2bd5c33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1077,6 +1077,7 @@ public void AaptError ([Values (true, false)] bool useAapt2)
}

[Test]
[Category ("dotnet")]
public void AndroidResourceChange ()
{
var proj = new XamarinAndroidApplicationProject ();
Expand All @@ -1088,15 +1089,10 @@ public void AndroidResourceChange ()
proj.Touch ("Resources\\layout\\Main.axml");
Assert.IsTrue (builder.Build (proj), "second build should succeed");

var targets = new [] {
"_ResolveLibraryProjectImports",
"_GenerateJavaStubs",
"_CompileJava",
"_CompileToDalvik",
};
foreach (var target in targets) {
Assert.IsTrue (builder.Output.IsTargetSkipped (target), $"`{target}` should be skipped!");
}
builder.Output.AssertTargetIsSkipped ("_ResolveLibraryProjectImports");
builder.Output.AssertTargetIsSkipped ("_GenerateJavaStubs");
builder.Output.AssertTargetIsSkipped ("_CompileJava");
builder.Output.AssertTargetIsSkipped ("_CompileToDalvik");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ public virtual void UpdateProjectFiles (string directory, IEnumerable<ProjectRes
var subname = fi.FullName.Substring (dirFullPath.Length).Replace ('\\', '/');
if (subname.StartsWith ("bin", StringComparison.OrdinalIgnoreCase) || subname.StartsWith ("obj", StringComparison.OrdinalIgnoreCase))
continue;
if (subname.Equals ("NuGet.config", StringComparison.OrdinalIgnoreCase))
continue;
if (subname.EndsWith (".log", StringComparison.OrdinalIgnoreCase) || subname.EndsWith (".binlog", StringComparison.OrdinalIgnoreCase))
continue;
if (!projectFiles.Any (p => p.Path != null && p.Path.Replace ('\\', '/').Equals (subname))) {
fi.Delete ();
}
Expand Down

0 comments on commit 2bd5c33

Please sign in to comment.