diff --git a/src/Templates/src/templates/maui-blazor/.template.config/template.json b/src/Templates/src/templates/maui-blazor/.template.config/template.json index c5692f03d6d0..ad0e9f91211e 100644 --- a/src/Templates/src/templates/maui-blazor/.template.config/template.json +++ b/src/Templates/src/templates/maui-blazor/.template.config/template.json @@ -94,7 +94,7 @@ "steps": [ { "regex": "[^a-z0-9_\\.]", - "replacement": "_" + "replacement": "" } ] } diff --git a/src/Templates/src/templates/maui-mobile/.template.config/template.json b/src/Templates/src/templates/maui-mobile/.template.config/template.json index 8abb57f3c68a..058875bdd23f 100644 --- a/src/Templates/src/templates/maui-mobile/.template.config/template.json +++ b/src/Templates/src/templates/maui-mobile/.template.config/template.json @@ -98,7 +98,7 @@ "steps": [ { "regex": "[^a-z0-9_\\.]", - "replacement": "_" + "replacement": "" } ] } diff --git a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs index 53b3087746ba..38f0175eac95 100644 --- a/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs +++ b/src/TestUtils/src/Microsoft.Maui.IntegrationTests/TemplateTests.cs @@ -1,3 +1,4 @@ +using System.Xml.Linq; using Microsoft.Maui.IntegrationTests.Apple; namespace Microsoft.Maui.IntegrationTests @@ -47,6 +48,41 @@ public void Build(string id, string framework, string config, bool shouldPack) $"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors."); } + [Test] + // with spaces + [TestCase("maui", "Project Space", "projectspace")] + [TestCase("maui-blazor", "Project Space", "projectspace")] + [TestCase("mauilib", "Project Space", "projectspace")] + // with invalid characters + [TestCase("maui", "Project@Symbol", "projectsymbol")] + [TestCase("maui-blazor", "Project@Symbol", "projectsymbol")] + [TestCase("mauilib", "Project@Symbol", "projectsymbol")] + public void BuildsWithSpecialCharacters(string id, string projectName, string expectedId) + { + var projectDir = Path.Combine(TestDirectory, projectName); + var projectFile = Path.Combine(projectDir, $"{projectName}.csproj"); + + Assert.IsTrue(DotnetInternal.New(id, projectDir, DotNetCurrent), + $"Unable to create template {id}. Check test output for errors."); + + EnableTizen(projectFile); + + // libraries do not have application IDs + if (id != "mauilib") + { + var doc = XDocument.Load(projectFile); + var appId = doc.Root! + .Elements("PropertyGroup") + .Elements("ApplicationId") + .Single() + .Value; + Assert.AreEqual($"com.companyname.{expectedId}", appId); + } + + Assert.IsTrue(DotnetInternal.Build(projectFile, "Debug", properties: BuildProps, msbuildWarningsAsErrors: true), + $"Project {Path.GetFileName(projectFile)} failed to build. Check test output/attachments for errors."); + } + [Test] // Parameters: short name, target framework, build config, use pack target [TestCase("maui", DotNetPrevious, "Debug", false)]