Skip to content

Commit 7234bbe

Browse files
[xamlc] enable for $(Configuration) names like ReleaseProd (#14638)
Context: #14591 (comment) In testing a customer project, I found that using a non-standard `$(Configuration)` name like `ReleaseProd` disables XamlC. In a30e243, we added a check for `$(Configuration)` to be exactly `Release`. Let's invert this check to be `!= Debug`. I also added a test to verify this works. This seems like a better default for customers, as it seems a lot worse for a `ReleaseProd` build to have XamlC off than a `DebugProd` build to accidentally have XamlC on. Asking around, but the .NET SDK doesn't appear to do anything special for `$(Optimize)` and `$(DebugSymbols)` related to `$(Configuration)`: https://github.com/dotnet/sdk/blob/7d23e9d3e4aad58a5b497d8d91a50ffdf148b238/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.props#L46-L54
1 parent 0c5a52d commit 7234bbe

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
Condition=" '$(DesignTimeBuild)' != 'True' AND '@(MauiXaml)' != ''">
149149
<PropertyGroup>
150150
<_MauiXamlCValidateOnly>$(MauiXamlCValidateOnly)</_MauiXamlCValidateOnly>
151-
<_MauiXamlCValidateOnly Condition="'$(Configuration)' != 'Release' AND '$(_MauiForceXamlCForDebug)' != 'True'">True</_MauiXamlCValidateOnly>
151+
<_MauiXamlCValidateOnly Condition="'$(Configuration)' == 'Debug' AND '$(_MauiForceXamlCForDebug)' != 'True'">True</_MauiXamlCValidateOnly>
152152
<_MauiXamlCValidateOnly Condition="'$(BuildingForLiveUnitTesting)' == 'True' ">True</_MauiXamlCValidateOnly>
153153
</PropertyGroup>
154154
<XamlCTask

src/Controls/tests/Xaml.UnitTests/MSBuild/MSBuildTests.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ static string GetTfm()
7272
public void SetUp()
7373
{
7474
testDirectory = TestContext.CurrentContext.TestDirectory;
75-
tempDirectory = IOPath.Combine(testDirectory, "temp", TestContext.CurrentContext.Test.Name);
75+
tempDirectory = IOPath.Combine(testDirectory, "temp",
76+
TestContext.CurrentContext.Test.Name
77+
.Replace('"', '_')
78+
.Replace('(', '_')
79+
.Replace(')', '_'));
7680
intermediateDirectory = IOPath.Combine(tempDirectory, "obj", "Debug", GetTfm());
7781
Directory.CreateDirectory(tempDirectory);
7882

@@ -259,22 +263,29 @@ public void BuildAProject()
259263

260264
// Tests the MauiXamlCValidateOnly=True MSBuild property
261265
[Test]
262-
public void ValidateOnly()
266+
public void ValidateOnly([Values("Debug", "Release", "ReleaseProd")] string configuration)
263267
{
264268
var project = NewProject();
265269
project.Add(AddFile("MainPage.xaml", "MauiXaml", Xaml.MainPage));
266270
var projectFile = IOPath.Combine(tempDirectory, "test.csproj");
267271
project.Save(projectFile);
268-
Build(projectFile, additionalArgs: "-p:MauiXamlCValidateOnly=True");
272+
intermediateDirectory = IOPath.Combine(tempDirectory, "obj", configuration, GetTfm());
273+
Build(projectFile, additionalArgs: $"-c {configuration}");
269274

270275
var testDll = IOPath.Combine(intermediateDirectory, "test.dll");
271276
AssertExists(testDll, nonEmpty: true);
272-
using (var assembly = AssemblyDefinition.ReadAssembly(testDll))
277+
using var assembly = AssemblyDefinition.ReadAssembly(testDll);
278+
var resources = assembly.MainModule.Resources.OfType<EmbeddedResource>().Select(e => e.Name).ToArray();
279+
if (configuration == "Debug")
273280
{
274281
// XAML files should remain as EmbeddedResource
275-
var resources = assembly.MainModule.Resources.OfType<EmbeddedResource>().Select(e => e.Name).ToArray();
276282
CollectionAssert.Contains(resources, "test.MainPage.xaml");
277283
}
284+
else
285+
{
286+
// XAML files should *not* remain as EmbeddedResource
287+
CollectionAssert.DoesNotContain(resources, "test.MainPage.xaml");
288+
}
278289
}
279290

280291
[Test]

0 commit comments

Comments
 (0)