Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building templates on a non-Windows machine is broken #4871

Closed
eerhardt opened this issue Feb 23, 2022 · 0 comments · Fixed by #4991
Closed

Building templates on a non-Windows machine is broken #4871

eerhardt opened this issue Feb 23, 2022 · 0 comments · Fixed by #4991
Assignees
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions area-templates Project templates, Item Templates for Blazor and MAUI fixed-in-6.0.300-rc.1 Look for this fix in 6.0.300-rc.1! platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working

Comments

@eerhardt
Copy link
Member

Description

When building on a macOS machine, we are using MSBuild to template some .json files. These .json files have backslashes in them \":

"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",

However, when we run this file through WriteLinesToFile task in MSBuild, the backslashes are getting flipped to front slashes:

<Target Name="_UpdateTemplateVersions" DependsOnTargets="SetVersions">
<ItemGroup>
<_TemplateJsonFile Include="templates\*\.template.config\template.json" />
<_TemplateJsonFileWithContent
Include="@(_TemplateJsonFile)"
Contents="$([System.IO.File]::ReadAllText('%(FullPath)')
.Replace('WINDOWSAPPSDK_VERSION_VALUE', '$(MicrosoftWindowsAppSDKPackageVersion)')
.Replace('WIN2D_VERSION_VALUE', '$(MicrosoftGraphicsWin2DPackageVersion)'))" />
<_TemplateCsprojFile Include="templates\*\*.csproj" />
<_TemplateCsprojFileWithContent
Include="@(_TemplateCsprojFile)"
Contents="$([System.IO.File]::ReadAllText('%(FullPath)')
.Replace('DOTNET_TFM_VALUE', '$(_MauiDotNetTfm)'))" />
<_TemplateReplacedFile Include="@(_TemplateJsonFile);@(_TemplateCsprojFile)" />
<_TemplateReplacedFileWithContent Include="@(_TemplateJsonFileWithContent);@(_TemplateCsprojFileWithContent)" />
</ItemGroup>
<WriteLinesToFile
File="@(_TemplateReplacedFileWithContent -> '$(IntermediateOutputPath)%(Identity)')"
Lines="%(Contents)"
Overwrite="true" />

In the binlog I see:

image

but that is getting flipped in the parameter to Lines:

image

To fix this, we might need to make our own "replacement" task that doesn't flip the slashes.

See dotnet/msbuild#1622 for more details on the underlying MSBuild bug.

Steps to Reproduce

  1. Build dotnet/maui on a macOS machine: dotnet cake --configuration="Release"
  2. Set your $PATH to include $REPO_ROOT/bin/dotnet
  3. dotnet new maui

Results

Error: Failed to load template from /Users/eerhardt/git/maui/bin/dotnet/template-packs/microsoft.maui.templates.6.0.200-dev.nupkg(/content/templates/maui-blazor/.template.config/template.json).
Details: Newtonsoft.Json.JsonReaderException: After parsing a value an unexpected character was encountered: d. Path 'primaryOutputs[0].condition', line 17, position 43.
   at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)
   at Newtonsoft.Json.JsonTextReader.Read()
   at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)
   at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader)
   at Microsoft.TemplateEngine.JExtensions.ReadJObjectFromIFile(IFile file)
   at Microsoft.TemplateEngine.Orchestrator.RunnableProjects.RunnableProjectGenerator.GetTemplatesAndLangpacksFromDir(IMountPoint source, IList`1& localizations)

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

All macOS versions

Did you find any workaround?

Use the template packages from a Windows build. Or use a Windows build to make the templated app and copy it to the macOS.

Relevant log output

No response

@eerhardt eerhardt added the t/bug Something isn't working label Feb 23, 2022
@Eilon Eilon added area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions area-templates Project templates, Item Templates for Blazor and MAUI labels Feb 28, 2022
@Eilon Eilon self-assigned this Mar 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Apr 6, 2022
@samhouts samhouts added the fixed-in-6.0.300-rc.1 Look for this fix in 6.0.300-rc.1! label Feb 17, 2023
@samhouts samhouts added the platform/macOS 🍏 macOS / Mac Catalyst label Feb 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-infrastructure CI, Maestro / Coherency, upstream dependencies/versions area-templates Project templates, Item Templates for Blazor and MAUI fixed-in-6.0.300-rc.1 Look for this fix in 6.0.300-rc.1! platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants