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

Restore postAction does not work when primaryOutputs renamed with sourceName #2068

Closed
npuc85 opened this issue Aug 13, 2019 · 4 comments
Closed
Assignees
Labels
size:5.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.

Comments

@npuc85
Copy link

npuc85 commented Aug 13, 2019

My template includes 3 projects:

  • src/My.Project.csproj
  • test/integration/My.Project.Test.Integration.csproj
  • test/unit/My.Project.Test.Unit.csproj

I am utilizing the "sourceName" property of the template.json to rename these to whatever name is passed into dotnet new, and I want to run restore on all 3 of the projects to restore nuget packages. My template.json looks something like this:

{
  ...
  "shortName": "mytemplate",
  "sourceName": "My.Project",
  "preferNameDirectory": false,
  "primaryOutputs": [
    {
      "path": "src\\My.Project.csproj"
    },
    {
      "path": "test\\unit\\My.Project.Test.Unit.csproj"
    },
    {
      "path": "test\\integration\\My.Project.Test.Integration.csproj"
    }
  ],
  "postActions": [
    {
      "condition": "(!skipRestore)",
      "description": "Restore NuGet packages required by this project.",
      "manualInstructions": [
        {
          "text": "Run 'dotnet restore'"
        }
      ],
      "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
      "continueOnError": true
    }
  ],
  "symbols": {
    "skipRestore": {
      "type": "parameter",
      "datatype": "bool",
      "description": "If specified, skips the automatic restore of the project on creation.",
      "defaultValue": "false"
    }
  }
}

When I install the template and run dotnet new mytemplate -n A.Project.Name I get all 3 projects in the correct folders with the names I expect (.\src\A.Project.Name.csproj, .\test\integration\A.Project.Name.Test.Integration.csproj, .\src\A.Project.Name.Test.Unit.csproj), and it does attempt to run the restore post action for each project, but it fails because it's trying to restore the actual names that are in my primary outputs. It is trying to restore src\My.Project.csproj, which obviously does not exist because it was renamed to src\A.Project.Name.csproj

@davidortinau
Copy link

I'm having the same issue.

Processing post-creation actions...
Running 'dotnet restore' on CometApp3/NewApp.iOS\NewApp.iOS.csproj...
MSBUILD : error MSB1009: Project file does not exist.
Switch: CometApp3/NewApp.iOS/NewApp.iOS.csproj

@sayedihashimi is there a workaround for this?

Looking to see if I could contribute a fix, but still learning the code. It looks like right about here the restore process needs to account for the provided name replacing sourceName.

string pathToRestore = !string.IsNullOrEmpty(outputBasePath) ? Path.Combine(outputBasePath, output.Path) : output.Path;

@phenning
Copy link
Contributor

phenning commented Sep 6, 2019

Try using forward slashes as path separators instead of windows style separators. There appears to be an issue with mapping the source renames in primary outputs which use windows path separators.

@donJoseLuis donJoseLuis added needsprioritization triaged The issue was evaluated by the triage team, placed on correct area, next action defined. labels Mar 20, 2020
@donJoseLuis
Copy link
Contributor

Hello @davidortinau , how did it go with phenning's work around?

@AR-May
Copy link
Member

AR-May commented Sep 30, 2020

The workaround works well for my test templates.

I normalized primary outputs so they should start to work with backslashes as path separators also. I am closing the issue, it seems nothing more should be done on that. Please do not hesitate to reopen the issue if anything comes up.

@AR-May AR-May closed this as completed Sep 30, 2020
vlada-shubina pushed a commit to vlada-shubina/templating that referenced this issue Dec 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:5.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

5 participants