diff options
| author | Rob Mensching <rob@firegiant.com> | 2025-12-15 01:24:03 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2025-12-15 11:35:30 -0800 |
| commit | 101fc4ece59306c09e7871ed14c51b46fd958f27 (patch) | |
| tree | 11eee40598ad7ed9557e7b8968fcf3cc16a6bf41 /src | |
| parent | eef158245d1404d91083454a58ba340e07e91f01 (diff) | |
| download | wix-101fc4ece59306c09e7871ed14c51b46fd958f27.tar.gz wix-101fc4ece59306c09e7871ed14c51b46fd958f27.tar.bz2 wix-101fc4ece59306c09e7871ed14c51b46fd958f27.zip | |
Block use of TargetFramework and TargetFrameworks in .wixproj
Setting these to anything but the default in the WiX Toolset Sdk will create
problems with project restore. Ensure nothing changes.
Resolves 7925
Diffstat (limited to 'src')
6 files changed, 112 insertions, 0 deletions
diff --git a/src/wix/WixToolset.Sdk/tools/wix.targets b/src/wix/WixToolset.Sdk/tools/wix.targets index 4de5835f..ddc83052 100644 --- a/src/wix/WixToolset.Sdk/tools/wix.targets +++ b/src/wix/WixToolset.Sdk/tools/wix.targets | |||
| @@ -178,6 +178,32 @@ | |||
| 178 | <BindVariable Include="$(WixVariables)" Condition=" '$(WixVariables)' != '' " /> | 178 | <BindVariable Include="$(WixVariables)" Condition=" '$(WixVariables)' != '' " /> |
| 179 | </ItemGroup> | 179 | </ItemGroup> |
| 180 | 180 | ||
| 181 | |||
| 182 | <!-- | ||
| 183 | *********************************************************************************************** | ||
| 184 | *********************************************************************************************** | ||
| 185 | Restore Section | ||
| 186 | *********************************************************************************************** | ||
| 187 | *********************************************************************************************** | ||
| 188 | --> | ||
| 189 | <Target | ||
| 190 | Name="WixTargetFrameworkCheck" | ||
| 191 | BeforeTargets="_LoadRestoreGraphEntryPoints;CollectPackageReferences;Restore" | ||
| 192 | Condition=" ('$(TargetFrameworks)' != '' and '$(TargetFrameworks)' != 'native') or '$(TargetFramework)' != 'native' "> | ||
| 193 | |||
| 194 | <Error | ||
| 195 | Text="The TargetFrameworks property is not supported by the WiX Toolset. Remove the TargetFrameworks property from your project and try building again. TargetFrameworks = $(TargetFrameworks)" | ||
| 196 | File="$(MSBuildProjectFullPath)" | ||
| 197 | Code="WIX9001" | ||
| 198 | Condition=" '$(TargetFrameworks)' != '' " /> | ||
| 199 | |||
| 200 | <Error | ||
| 201 | Text="The TargetFramework property is not supported by the WiX Toolset. Remove the TargetFramework property from your project and try building again. TargetFramework = $(TargetFramework)" | ||
| 202 | File="$(MSBuildProjectFullPath)" | ||
| 203 | Code="WIX9002" | ||
| 204 | Condition=" '$(TargetFramework)' != 'native' " /> | ||
| 205 | </Target> | ||
| 206 | |||
| 181 | <!-- | 207 | <!-- |
| 182 | *********************************************************************************************** | 208 | *********************************************************************************************** |
| 183 | *********************************************************************************************** | 209 | *********************************************************************************************** |
diff --git a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs index ba5093ac..22cb0a75 100644 --- a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs +++ b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs | |||
| @@ -850,6 +850,64 @@ namespace WixToolsetTest.Sdk | |||
| 850 | [DataRow(BuildSystem.DotNetCoreSdk)] | 850 | [DataRow(BuildSystem.DotNetCoreSdk)] |
| 851 | [DataRow(BuildSystem.MSBuild)] | 851 | [DataRow(BuildSystem.MSBuild)] |
| 852 | [DataRow(BuildSystem.MSBuild64)] | 852 | [DataRow(BuildSystem.MSBuild64)] |
| 853 | public void CannotBuildWithTargetFrameworks(BuildSystem buildSystem) | ||
| 854 | { | ||
| 855 | var sourceFolder = TestData.Get(@"TestData", "WithTargetFrameworkError"); | ||
| 856 | |||
| 857 | using (var fs = new TestDataFolderFileSystem()) | ||
| 858 | { | ||
| 859 | fs.Initialize(sourceFolder); | ||
| 860 | var baseFolder = Path.Combine(fs.BaseFolder, "TargetFrameworkError"); | ||
| 861 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 862 | var filesFolder = Path.Combine(binFolder, "Release", @"PFiles\"); | ||
| 863 | var projectPath = Path.Combine(baseFolder, "TargetFrameworkError.wixproj"); | ||
| 864 | |||
| 865 | var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, [ | ||
| 866 | "-Restore", | ||
| 867 | MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath) | ||
| 868 | ]); | ||
| 869 | |||
| 870 | var errors = GetDistinctErrorMessages(result.Output, baseFolder); | ||
| 871 | WixAssert.CompareLineByLine(new[] | ||
| 872 | { | ||
| 873 | @"<basefolder>\TargetFrameworkError.wixproj : error WIX9002: The TargetFramework property is not supported by the WiX Toolset. Remove the TargetFramework property from your project and try building again. TargetFramework = net472", | ||
| 874 | }, errors); | ||
| 875 | } | ||
| 876 | } | ||
| 877 | |||
| 878 | [TestMethod] | ||
| 879 | [DataRow(BuildSystem.DotNetCoreSdk)] | ||
| 880 | [DataRow(BuildSystem.MSBuild)] | ||
| 881 | [DataRow(BuildSystem.MSBuild64)] | ||
| 882 | public void CannotBuildWithTargetFramework(BuildSystem buildSystem) | ||
| 883 | { | ||
| 884 | var sourceFolder = TestData.Get(@"TestData", "WithTargetFrameworkError"); | ||
| 885 | |||
| 886 | using (var fs = new TestDataFolderFileSystem()) | ||
| 887 | { | ||
| 888 | fs.Initialize(sourceFolder); | ||
| 889 | var baseFolder = Path.Combine(fs.BaseFolder, "TargetFrameworksError"); | ||
| 890 | var binFolder = Path.Combine(baseFolder, @"bin\"); | ||
| 891 | var filesFolder = Path.Combine(binFolder, "Release", @"PFiles\"); | ||
| 892 | var projectPath = Path.Combine(baseFolder, "TargetFrameworksError.wixproj"); | ||
| 893 | |||
| 894 | var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, [ | ||
| 895 | "-Restore", | ||
| 896 | MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "WixMSBuildProps", MsbuildFixture.WixPropsPath) | ||
| 897 | ]); | ||
| 898 | |||
| 899 | var errors = GetDistinctErrorMessages(result.Output, baseFolder); | ||
| 900 | WixAssert.CompareLineByLine(new[] | ||
| 901 | { | ||
| 902 | @"<basefolder>\TargetFrameworksError.wixproj : error WIX9001: The TargetFrameworks property is not supported by the WiX Toolset. Remove the TargetFrameworks property from your project and try building again. TargetFrameworks = net8.0", | ||
| 903 | }, errors); | ||
| 904 | } | ||
| 905 | } | ||
| 906 | |||
| 907 | [TestMethod] | ||
| 908 | [DataRow(BuildSystem.DotNetCoreSdk)] | ||
| 909 | [DataRow(BuildSystem.MSBuild)] | ||
| 910 | [DataRow(BuildSystem.MSBuild64)] | ||
| 853 | public void CanBuildWithWarningWhenExtensionIsMissing(BuildSystem buildSystem) | 911 | public void CanBuildWithWarningWhenExtensionIsMissing(BuildSystem buildSystem) |
| 854 | { | 912 | { |
| 855 | var sourceFolder = TestData.Get(@"TestData", "WixlibMissingExtension"); | 913 | var sourceFolder = TestData.Get(@"TestData", "WixlibMissingExtension"); |
diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworkError/Package.wxs b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworkError/Package.wxs new file mode 100644 index 00000000..ac49711f --- /dev/null +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworkError/Package.wxs | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | ||
| 2 | <Package Id="WixTest.Package" Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation"> | ||
| 3 | <File Source="doesnotexist.txt" /> | ||
| 4 | </Package> | ||
| 5 | </Wix> | ||
diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworkError/TargetFrameworkError.wixproj b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworkError/TargetFrameworkError.wixproj new file mode 100644 index 00000000..3b6e1300 --- /dev/null +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworkError/TargetFrameworkError.wixproj | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | <Project> | ||
| 2 | <Import Project="$(WixMSBuildProps)" /> | ||
| 3 | |||
| 4 | <PropertyGroup> | ||
| 5 | <TargetFramework>net472</TargetFramework> | ||
| 6 | </PropertyGroup> | ||
| 7 | |||
| 8 | <Import Project="$(WixTargetsPath)" /> | ||
| 9 | </Project> | ||
diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworksError/Package.wxs b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworksError/Package.wxs new file mode 100644 index 00000000..ac49711f --- /dev/null +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworksError/Package.wxs | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | <Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"> | ||
| 2 | <Package Id="WixTest.Package" Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation"> | ||
| 3 | <File Source="doesnotexist.txt" /> | ||
| 4 | </Package> | ||
| 5 | </Wix> | ||
diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworksError/TargetFrameworksError.wixproj b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworksError/TargetFrameworksError.wixproj new file mode 100644 index 00000000..b3f4777f --- /dev/null +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/WithTargetFrameworkError/TargetFrameworksError/TargetFrameworksError.wixproj | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | <Project> | ||
| 2 | <Import Project="$(WixMSBuildProps)" /> | ||
| 3 | |||
| 4 | <PropertyGroup> | ||
| 5 | <TargetFrameworks>net8.0</TargetFrameworks> | ||
| 6 | </PropertyGroup> | ||
| 7 | |||
| 8 | <Import Project="$(WixTargetsPath)" /> | ||
| 9 | </Project> | ||
