question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Template engine not renaming primaryOutputs paths

See original GitHub issue

This issue has been fixed in (#1566), but I can’t get it to work, here is my template.json:

{
  "$schema": "http://json.schemastore.org/template",
  "author": "Me",
  "classifications": [
    "Common",
    "Console",
    "C#8"
  ],
  "identity": "ExampleTemplate.AsyncProject",
  "name": "Example templates: async project",
  "shortName": "new-template",
  "sourceName": "$safeProjectName$",
  "tags": {
    "language": "C#",
    "type": "project"
  },
  "primaryOutputs": [
    {
      "path": "/$safeProjectName$/$safeProjectName$.csproj"
    }
  ],
  "postActions": [
    {
      "description": "Restore NuGet packages required by this project.",
      "manualInstructions": [
        {
          "text": "Run 'dotnet restore'"
        }
      ],
      "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
      "continueOnError": true
    }
  ]
}

when I am running dotnet new new-template -n NewProject will receive following error:

Processing post-creation actions...
Running 'dotnet restore' on /$safeProjectName$/$safeProjectName$.csproj...
MSBUILD : error MSB1001: Unknown switch.
Switch: /$safeProjectName$/$safeProjectName$.csproj

For switch syntax, type "MSBuild -help"

Restore failed.
Post action failed.
Description: Restore NuGet packages required by this project.
Manual instructions: Run 'dotnet restore'

That’s because $safeProjectName$ not renamed to NewProject.

dotnet new --debug:version result:

Welcome to .NET Core 3.1!
---------------------
SDK Version: 3.1.404

Repo:

https://github.com/ccpu/dotnet-template-primaryOutputs-issue

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
vlada-shubinacommented, Dec 7, 2020

@DavidKarlas David Karlas FTE thanks for the advice, removing / did solve the problem, however, I have discovered a new problem:

To prevent errors related to the internal references, I have to replace the $safeProjectName$.csproj to $safeProjectName$.csproj.xml; template engine should rename it as configured below:

  "sources": [
    {
      "modifiers": [
        {
          "rename": {
            "$safeProjectName$.csproj.xml": "$safeProjectName$.csproj"
          }
        }
      ]
    }
  ],

https://github.com/ccpu/dotnet-template-primaryOutputs-issue/blob/7257bc538873a6f12d4446e598d9575f8e70003d/.template.config/template.json#L22

Template engine converts the file name correctly, however dotnet restore throw the same error as above.

Any suggestion for this issue?

@ccpu this is a known issue and will be fixed in https://github.com/dotnet/templating/issues/2453. I will keep this ticket opened until fix is merged. Thank you.

1reaction
DavidKarlascommented, Dec 7, 2020

I think problem is that primaryOutput thats with / : https://github.com/ccpu/dotnet-template-primaryOutputs-issue/blob/main/.template.config/template.json#L19 should be:

"path": "$safeProjectName$/$safeProjectName$.csproj"

Leaving issue open to consider doing some basic check that primaryOutput don’t start with /

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Primary Outputs for Post Actions · dotnet/templating ...
Renaming. When using renames in source modifiers, make sure that primary output path contains the filename after source based file rename is ...
Read more >
Net Core 2.0 project template $safeprojectname
Let's say you only want to replace "Template" and not "Template.Tools.WebAPI", just change the value of SourceName to "Template".
Read more >
Templating Projects On .NET Core. by Roman Patutin
To rename a project, we can use the framework's built-in functionality. It's enough to specify the sourceName and primaryOutputs keys to open ...
Read more >
`Guids` section of `template.json` - GitHub
In this field you define the values shown as Tags in `dotnet new`|no| |`name`|The name for the template. This is displayed as the...
Read more >
How to build a .NET template and use it within Visual Studio ...
When you create a new solution using this template every .csproj file and the .sln file will be renamed by the template engine...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found