Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 3ebc7df

Browse files
[tests] expanded testing around design-time builds
Really need to make sure design-time builds work, as intellisense would break!
1 parent 6121067 commit 3ebc7df

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

Xamarin.Forms.Xaml.UnitTests/MSBuild/MSBuildTests.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ public void LinkedFile ([Values (false, true)] bool sdkStyle)
288288
}
289289

290290
//https://github.com/dotnet/project-system/blob/master/docs/design-time-builds.md
291+
//https://daveaglick.com/posts/running-a-design-time-build-with-msbuild-apis
291292
[Test]
292293
public void DesignTimeBuild ([Values (false, true)] bool sdkStyle)
293294
{
@@ -296,13 +297,33 @@ public void DesignTimeBuild ([Values (false, true)] bool sdkStyle)
296297
var projectFile = Path.Combine (tempDirectory, "test.csproj");
297298
project.Save (projectFile);
298299
RestoreIfNeeded (projectFile, sdkStyle);
299-
Build (projectFile, "Compile", "/p:DesignTimeBuild=True /p:BuildingInsideVisualStudio=True /p:BuildingProject=False");
300+
Build (projectFile, "CompileDesignTime", "/p:DesignTimeBuild=True /p:BuildingInsideVisualStudio=True /p:SkipCompilerExecution=True /p:ProvideCommandLineArgs=True");
300301

301-
AssertExists (Path.Combine (intermediateDirectory, "test.dll"), nonEmpty: true);
302-
AssertExists (Path.Combine (intermediateDirectory, "Pages", "MainPage.xaml.g.cs"), nonEmpty: true);
303-
AssertExists (Path.Combine (intermediateDirectory, "XamlC.stamp"));
302+
var assembly = Path.Combine (intermediateDirectory, "test.dll");
303+
var mainPageXamlG = Path.Combine (intermediateDirectory, "Pages", "MainPage.xaml.g.cs");
304+
var xamlCStamp = Path.Combine (intermediateDirectory, "XamlC.stamp");
305+
306+
//The assembly should not be compiled
307+
AssertDoesNotExist (assembly);
308+
AssertExists (mainPageXamlG, nonEmpty: true);
309+
AssertExists (xamlCStamp);
310+
311+
var expectedXamlG = new FileInfo (mainPageXamlG).LastWriteTimeUtc;
312+
var expectedXamlC = new FileInfo (xamlCStamp).LastWriteTimeUtc;
313+
314+
//Build again, a full build
315+
Build (projectFile);
316+
AssertExists (assembly, nonEmpty: true);
317+
AssertExists (mainPageXamlG, nonEmpty: true);
318+
AssertExists (xamlCStamp);
319+
320+
var actualXamlG = new FileInfo (mainPageXamlG).LastWriteTimeUtc;
321+
var actualXamlC = new FileInfo (xamlCStamp).LastWriteTimeUtc;
322+
Assert.AreEqual (expectedXamlG, actualXamlG, $"Timestamps should match for {mainPageXamlG}.");
323+
Assert.AreNotEqual (expectedXamlC, actualXamlC, $"Timestamps should *not* match for {xamlCStamp}.");
304324
}
305325

326+
//I believe the designer might invoke this target manually
306327
[Test]
307328
public void UpdateDesignTimeXaml ([Values (false, true)] bool sdkStyle)
308329
{
@@ -314,6 +335,7 @@ public void UpdateDesignTimeXaml ([Values (false, true)] bool sdkStyle)
314335
Build (projectFile, "UpdateDesignTimeXaml");
315336

316337
AssertExists (Path.Combine (intermediateDirectory, "Pages", "MainPage.xaml.g.cs"), nonEmpty: true);
338+
AssertDoesNotExist (Path.Combine (intermediateDirectory, "XamlC.stamp"));
317339
}
318340

319341
[Test]

0 commit comments

Comments
 (0)