Restore postAction does not work when primaryOutputs renamed with sourceName
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
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.
https://github.com/dotnet/templating/blob/e92ed67914f2fffe79fbce1e6cac4096e3ccfd19/src/Microsoft.TemplateEngine.Cli/PostActionProcessors/DotnetRestorePostActionProcessor.cs#L107
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.
Hello @davidortinau , how did it go with phenning's work around?
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.