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

Commit 5d9facb

Browse files
[windows] fix for when $(VsInstallRoot) is missing a trailing slash (#9)
Usage of Xamarin.Legacy.Sdk on xamarin-android's CI fails with: error MSB4057: The target "_GetRestoreSettingsPerFramework" does not exist in the project. Reviewing the build logs, `Xamarin.Android.CSharp.targets` fails to be imported at all due to: _LegacyExtensionsPath = C:\Program Files (x86)\Microsoft Visual Studio\2019\EnterpriseMSBuild It appears that if either `%VSINSTALLDIR%` or `$(VsInstallRoot)` were missing a trailing slash, then `$(_LegacyExtensionsPath)` would be incorrect. First I added a new `samples/tests` folder, to start throwing in one-off projects as pseudo-unit tests. Or maybe integration tests is a better term? `dotnet build samples.sln` should be the equivalent of running tests in this repo. Next, I moved the `$(VsInstallRoot)` logic to its own `Xamarin.VsInstallRoot.targets` file to be shared between iOS and Android. Lastly, I added the appropriate `EnsureTrailingSlash()` call: https://docs.microsoft.com/visualstudio/msbuild/property-functions#msbuild-ensuretrailingslash
1 parent 43391b2 commit 5d9facb

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

samples/samples.sln

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hello", "Hello\Hello.csproj
77
EndProject
88
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JavaBinding", "JavaBinding\JavaBinding.csproj", "{67EB8FFE-826F-445A-A8E6-8DAFB3A2E65F}"
99
EndProject
10+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VsInstallRoot", "tests\VsInstallRoot\VsInstallRoot.csproj", "{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{CFDB900E-AD95-43C6-BF87-FEE446EBF78B}"
13+
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{149B3F40-F69B-4A1B-A499-F533B9717040}"
15+
EndProject
1016
Global
1117
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1218
Debug|Any CPU = Debug|Any CPU
@@ -41,10 +47,27 @@ Global
4147
{67EB8FFE-826F-445A-A8E6-8DAFB3A2E65F}.Release|x64.Build.0 = Release|Any CPU
4248
{67EB8FFE-826F-445A-A8E6-8DAFB3A2E65F}.Release|x86.ActiveCfg = Release|Any CPU
4349
{67EB8FFE-826F-445A-A8E6-8DAFB3A2E65F}.Release|x86.Build.0 = Release|Any CPU
50+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Debug|x64.ActiveCfg = Debug|Any CPU
53+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Debug|x64.Build.0 = Debug|Any CPU
54+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Debug|x86.ActiveCfg = Debug|Any CPU
55+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Debug|x86.Build.0 = Debug|Any CPU
56+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU
57+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Release|x64.ActiveCfg = Release|Any CPU
59+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Release|x64.Build.0 = Release|Any CPU
60+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Release|x86.ActiveCfg = Release|Any CPU
61+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D}.Release|x86.Build.0 = Release|Any CPU
4462
EndGlobalSection
4563
GlobalSection(SolutionProperties) = preSolution
4664
HideSolutionNode = FALSE
4765
EndGlobalSection
66+
GlobalSection(NestedProjects) = preSolution
67+
{5E34FB3D-487C-433A-8A49-96444046888D} = {149B3F40-F69B-4A1B-A499-F533B9717040}
68+
{67EB8FFE-826F-445A-A8E6-8DAFB3A2E65F} = {149B3F40-F69B-4A1B-A499-F533B9717040}
69+
{5B390F99-D000-4DB0-98C4-8FC0F4AC2D9D} = {CFDB900E-AD95-43C6-BF87-FEE446EBF78B}
70+
EndGlobalSection
4871
GlobalSection(ExtensibilityGlobals) = postSolution
4972
SolutionGuid = {A49B40B9-4E4D-4B19-B124-9B19C41B5759}
5073
EndGlobalSection

samples/tests/VsInstallRoot/Foo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public class Foo { }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Xamarin.Legacy.Sdk">
2+
<Import Condition=" $([MSBuild]::IsOSPlatform ('windows')) " Project="../../../src/Xamarin.Legacy.Sdk/Sdk/Xamarin.VsInstallRoot.targets" />
3+
<PropertyGroup>
4+
<TargetFrameworks>monoandroid11.0;xamarin.ios10;net6.0-android;net6.0-ios</TargetFrameworks>
5+
<VsInstallRoot Condition=" HasTrailingSlash($(VsInstallRoot)) ">$(VsInstallRoot.TrimEnd ('/').TrimEnd ('\'))</VsInstallRoot>
6+
</PropertyGroup>
7+
</Project>

src/Xamarin.Legacy.Sdk/Sdk/Xamarin.Legacy.Android.targets

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66
<PropertyGroup Condition=" !Exists('$(MSBuildExtensionsPath)/Xamarin/Android/Xamarin.Android.CSharp.targets') ">
77
<_FixupsNeeded>true</_FixupsNeeded>
88
</PropertyGroup>
9-
<PropertyGroup Condition=" '$(_FixupsNeeded)' == 'true' and $([MSBuild]::IsOSPlatform ('windows')) ">
10-
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' and '$(VSINSTALLDIR)' != '' ">$(VSINSTALLDIR)</VsInstallRoot>
11-
<!-- At the moment 16.9 is in Preview, prefer it -->
12-
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' and Exists ('$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Preview/') ">$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Preview/</VsInstallRoot>
13-
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' ">$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Enterprise/</VsInstallRoot>
14-
<TargetFrameworkRootPath>$(VsInstallRoot)Common7/IDE/ReferenceAssemblies/Microsoft/Framework/</TargetFrameworkRootPath>
15-
<_LegacyExtensionsPath>$(VsInstallRoot)MSBuild</_LegacyExtensionsPath>
16-
</PropertyGroup>
9+
<Import
10+
Condition=" '$(_FixupsNeeded)' == 'true' and $([MSBuild]::IsOSPlatform ('windows')) "
11+
Project="Xamarin.VsInstallRoot.targets"
12+
/>
1713
<PropertyGroup Condition=" '$(_FixupsNeeded)' == 'true' and $([MSBuild]::IsOSPlatform ('osx')) ">
1814
<XamarinAndroidInstallPath Condition=" '$(XamarinAndroidInstallPath)' == '' ">/Library/Frameworks/Xamarin.Android.framework/</XamarinAndroidInstallPath>
1915
<TargetFrameworkRootPath>$(XamarinAndroidInstallPath)Libraries/xbuild-frameworks/</TargetFrameworkRootPath>

src/Xamarin.Legacy.Sdk/Sdk/Xamarin.Legacy.iOS.targets

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
<PropertyGroup Condition=" !Exists('$(MSBuildExtensionsPath)/Xamarin/iOS/Xamarin.iOS.CSharp.targets') ">
77
<_FixupsNeeded>true</_FixupsNeeded>
88
</PropertyGroup>
9+
<Import
10+
Condition=" '$(_FixupsNeeded)' == 'true' and $([MSBuild]::IsOSPlatform ('windows')) "
11+
Project="Xamarin.VsInstallRoot.targets"
12+
/>
913
<PropertyGroup Condition=" '$(_FixupsNeeded)' == 'true' and $([MSBuild]::IsOSPlatform ('windows')) ">
10-
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' and '$(VSINSTALLDIR)' != '' ">$(VSINSTALLDIR)</VsInstallRoot>
11-
<!-- At the moment 16.9 is in Preview, prefer it -->
12-
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' and Exists ('$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Preview/') ">$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Preview/</VsInstallRoot>
13-
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' ">$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Enterprise/</VsInstallRoot>
14-
<TargetFrameworkRootPath>$(VsInstallRoot)Common7/IDE/ReferenceAssemblies/Microsoft/Framework/</TargetFrameworkRootPath>
15-
<_LegacyExtensionsPath>$(VsInstallRoot)MSBuild</_LegacyExtensionsPath>
1614
<FrameworkPathOverride>$(TargetFrameworkRootPath)Xamarin.iOS/v1.0/</FrameworkPathOverride>
1715
</PropertyGroup>
1816
<PropertyGroup Condition=" '$(_FixupsNeeded)' == 'true' and $([MSBuild]::IsOSPlatform ('osx')) ">
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- This files assumes it is imported on Windows-only -->
2+
<Project>
3+
<PropertyGroup>
4+
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' and '$(VSINSTALLDIR)' != '' ">$(VSINSTALLDIR)</VsInstallRoot>
5+
<!-- At the moment 16.9 is in Preview, prefer it -->
6+
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' and Exists ('$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Preview/') ">$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Preview/</VsInstallRoot>
7+
<VsInstallRoot Condition=" '$(VsInstallRoot)' == '' ">$(MSBuildProgramFiles32)/Microsoft Visual Studio/2019/Enterprise/</VsInstallRoot>
8+
<TargetFrameworkRootPath>$([MSBuild]::EnsureTrailingSlash($(VsInstallRoot)))Common7/IDE/ReferenceAssemblies/Microsoft/Framework/</TargetFrameworkRootPath>
9+
<_LegacyExtensionsPath>$([MSBuild]::EnsureTrailingSlash($(VsInstallRoot)))MSBuild</_LegacyExtensionsPath>
10+
</PropertyGroup>
11+
</Project>

0 commit comments

Comments
 (0)