From 6a7df4b88e77d16bf619e25cd6d6f49cbef10319 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 26 Oct 2017 17:02:20 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tasks] Move DesignTime Cache files to designtime folder. The DesignTime build is generally run before any nuget packages have been restore. As a result we end up with empty cache files. Because those files exist and are considered uptodate, when the main build finally happens they are not re-generated. This causes errors like error: Error: No resource found that matches the given name: attr 'colorAccent'. on a new default template. So the DesignTime build should have its own set of cache files which do not conflict with the main build. This way when the main build runs the cache files will not be in place. --- .../Tests/Xamarin.Android.Build.Tests/BuildTest.cs | 10 +++++++++- .../Xamarin.Android.Common.targets | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs index 86aef0813f9..e333398d47d 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest.cs @@ -1790,19 +1790,27 @@ public void BuildBasicApplicationCheckPdb () [Test] public void BuildInDesignTimeMode ([Values(false, true)] bool useManagedParser) { + var path = Path.Combine ("temp", TestContext.CurrentContext.Test.Name); var proj = new XamarinAndroidApplicationProject () { IsRelease = true, }; proj.SetProperty ("AndroidUseManagedDesignTimeResourceGenerator", useManagedParser.ToString ()); - using (var builder = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name), false ,false)) { + using (var builder = CreateApkBuilder (path, false ,false)) { builder.Verbosity = LoggerVerbosity.Diagnostic; builder.Target = "UpdateAndroidResources"; builder.Build (proj, parameters: new string[] { "DesignTimeBuild=true" }); Assert.IsFalse (builder.Output.IsTargetSkipped ("_CreatePropertiesCache"), "target \"_CreatePropertiesCache\" should have been run."); Assert.IsFalse (builder.Output.IsTargetSkipped ("_ResolveLibraryProjectImports"), "target \"_ResolveLibraryProjectImports\' should have been run."); + var librarycache = Path.Combine (Root, path, proj.IntermediateOutputPath, "designtime", "libraryprojectimports.cache"); + Assert.IsTrue (File.Exists (librarycache), $"'{librarycache}' should exist."); + librarycache = Path.Combine (Root, path, proj.IntermediateOutputPath, "libraryprojectimports.cache"); + Assert.IsFalse (File.Exists (librarycache), $"'{librarycache}' should not exist."); builder.Build (proj, parameters: new string[] { "DesignTimeBuild=true" }); Assert.IsFalse (builder.Output.IsTargetSkipped ("_CreatePropertiesCache"), "target \"_CreatePropertiesCache\" should have been run."); Assert.IsTrue (builder.Output.IsTargetSkipped ("_ResolveLibraryProjectImports"), "target \"_ResolveLibraryProjectImports\' should have been skipped."); + Assert.IsTrue (builder.Clean (proj), "Clean Should have succeeded"); + librarycache = Path.Combine (Root, path, proj.IntermediateOutputPath, "designtime", "libraryprojectimports.cache"); + Assert.IsFalse (File.Exists (librarycache), $"'{librarycache}' should exist."); } } diff --git a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets index e02a550664f..e005ec51c17 100755 --- a/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets +++ b/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets @@ -396,7 +396,11 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved. true True False + <_AndroidResourcePathsCache Condition=" '$(DesignTimeBuild)' == 'true' ">$(_AndroidDesignTimeResDirIntermediate)resourcepaths.cache + <_AndroidLibraryImportsCache Condition=" '$(DesignTimeBuild)' == 'true' ">$(_AndroidDesignTimeResDirIntermediate)libraryimports.cache + <_AndroidLibraryProjectImportsCache Condition=" '$(DesignTimeBuild)' == 'true' ">$(_AndroidDesignTimeResDirIntermediate)libraryprojectimports.cache +