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

Move files during template creation and maintain project rename #1553

Closed
Plac3hold3r opened this issue Jun 6, 2018 · 2 comments
Closed

Move files during template creation and maintain project rename #1553

Plac3hold3r opened this issue Jun 6, 2018 · 2 comments

Comments

@Plac3hold3r
Copy link

Hi

I'm struggling to find documentation describing if it is possible to move files and folder during template creation while maintaining the sourceName auto rename of the project and folder names. Is this possible with dotnet templating?

The template that I have been working on, can be found on GitHub. The use case I'm trying to cater for relates to an idea to support multiple projects structure types, for example (Related to Xamarin apps), a blank app, a single view based app or an app with a navigation menu.

Initially, I was thinking about including all the different types in a single project and excluding the files that do not relate to the chosen template option. However, this creates a bit of an issue as I lose the ability to test the template except through creating the output via the dotnet new cli. So I thought perhaps I could create a separate project on disk and move the chosen template option into the correct folder location and skip the others.

Example

SourceName = "MvxNative"

Structure on disk in template

./src/SingleView/MvxNative.Droid/{{ other files }}
./src/SingleView/MvxNative.Droid/MvxNative.Droid.cspoj
./src/NavigationMenu/MvxNative.Droid/{{ other files }}
./src/NavigationMenu/MvxNative.Droid/MvxNative.Droid.cspoj

dotnet new mvxnative -n "MyApp" --scaffold-type "navigation-menu"

Structure after move, but before rename

./src/MvxNative.Droid/{{ other files }}
./src/MvxNative/MvxNative.Droid/MvxNative.Droid.cspoj

Structure after move and rename

./src/MyApp.Droid/{{ other files }}
./src/MyApp.Droid/MyApp.Droid.cspoj

Perhaps there is an alternative, any help/advice would be greatly appreciated.

@Plac3hold3r Plac3hold3r changed the title Move files during template create and maintain project rename Move files during template creation and maintain project rename Jun 6, 2018
@seancpeters
Copy link
Contributor

If I understand your question correctly, the answer is yes, you can do both at the same time, as long as you have a new enough version of dotnet (I know 2.1.3 is sufficient). Some older versions had a bug where only 1 type of renaming operation would apply to a given file. In the example below, both the source name handling, and moving of files are handled by rename operations.

I setup a minimal template that I think accomplishes what you're asking for - in terms of file renames and moves. Here is the relevant parts of the template.json:

  "sourceName": "Company.ConsoleApplication1",
  "sources": [
    {
	  "modifiers": [
	    {
	      "condition": "(Pivot == \"Single\")",
		  "rename": { "SingleView/": "" },
		  "exclude": [ "src/NavigationMenu/**/*" ]
	    },
		{
		  "condition": "(Pivot == \"Navigation\")",
		  "rename": { "NavigationMenu/": "" },
		  "exclude": [ "src/SingleView/**/*" ]
		}
	  ]
	}
  ],
  "symbols": {
    "Pivot": {
	  "type": "parameter",
	  "description": "Demonstrates move & rename",
	  "datatype": "choice",
	  "choices": [
	    {
		  "choice": "Single",
		  "description": "Use the contents of SingleView"
		},
		{
		  "choice": "Navigation",
		  "description": "Use the contents of NavigationMenu"
		}
	  ],
	  "defaultValue": "Single"
	},
  },

And here is the file / directory structure of the source template:
moverename

@Plac3hold3r
Copy link
Author

Thank you @seancpeters that works perfectly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants