Skip to content

Commit 101fc4e

Browse files
committed
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
1 parent eef1582 commit 101fc4e

File tree

6 files changed

+112
-0
lines changed

6 files changed

+112
-0
lines changed

src/wix/WixToolset.Sdk/tools/wix.targets

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,32 @@
178178
<BindVariable Include="$(WixVariables)" Condition=" '$(WixVariables)' != '' " />
179179
</ItemGroup>
180180

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+
181207
<!--
182208
***********************************************************************************************
183209
***********************************************************************************************

src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,64 @@ public void CannotBuildMultiTargetingWixlibUsingExplicitSubsetOfTfmAndRid(BuildS
846846
}
847847
}
848848

849+
[TestMethod]
850+
[DataRow(BuildSystem.DotNetCoreSdk)]
851+
[DataRow(BuildSystem.MSBuild)]
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+
849907
[TestMethod]
850908
[DataRow(BuildSystem.DotNetCoreSdk)]
851909
[DataRow(BuildSystem.MSBuild)]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

0 commit comments

Comments
 (0)