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

Commit 7c48cfe

Browse files
[msbuild] improved lookup of Xamarin.Forms.targets in integration tests
Context: https://devdiv.visualstudio.com/0bdbc590-a062-4c3f-b0f6-9383f67865ee/_build/index?buildId=1717939 It looks like the test assemblies are now copied to a build staging directory on VSTS. We can rely on `BUILD_STAGINGDIRECTORY` to be set when running in VSTS, and use an alternative place to find `Xamarin.Forms.targets`. I also made the tests abort earlier if they can't find `Xamarin.Forms.targets`.
1 parent 760c358 commit 7c48cfe

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Xamarin.Forms.Xaml.UnitTests
1313
[TestFixture]
1414
public class MSBuildTests
1515
{
16-
static readonly string XamarinFormsTargets = Path.Combine ("..", "..", "..", "..", "..", ".nuspec", "Xamarin.Forms.targets");
16+
static readonly string XamarinFormsTargets = Path.Combine (".nuspec", "Xamarin.Forms.targets");
1717

1818
static readonly string [] references = new []
1919
{
@@ -120,7 +120,23 @@ XElement NewProject (bool sdkStyle)
120120

121121
if (!sdkStyle)
122122
project.Add (NewElement ("Import").WithAttribute ("Project", @"$(MSBuildBinPath)\Microsoft.CSharp.targets"));
123-
project.Add (NewElement ("Import").WithAttribute ("Project", XamarinFormsTargets));
123+
124+
var xamarinFormsTargets = Path.Combine (tempDirectory, "..", "..", "..", "..", "..", XamarinFormsTargets);
125+
if (!File.Exists (xamarinFormsTargets)) {
126+
//NOTE: VSTS we can use an environment variable
127+
// https://docs.microsoft.com/en-us/vsts/build-release/concepts/definitions/build/variables?view=vsts&tabs=batch#buildsourcesdirectory
128+
var sourcesDirectory = Environment.GetEnvironmentVariable ("BUILD_SOURCESDIRECTORY");
129+
if (!string.IsNullOrEmpty (sourcesDirectory)) {
130+
xamarinFormsTargets = Path.Combine (sourcesDirectory, XamarinFormsTargets);
131+
if (!File.Exists (xamarinFormsTargets)) {
132+
Assert.Fail ("Unable to find Xamarin.Forms.targets at path: " + xamarinFormsTargets);
133+
}
134+
} else {
135+
Assert.Fail ("Unable to find Xamarin.Forms.targets at path: " + xamarinFormsTargets);
136+
}
137+
}
138+
139+
project.Add (NewElement ("Import").WithAttribute ("Project", Path.GetFullPath (xamarinFormsTargets)));
124140
return project;
125141
}
126142

0 commit comments

Comments
 (0)