templating
templating copied to clipboard
Change .templateengine folder path
I would like to setup a dotnet sdk environment on a usb drive in a portable
mode. The idea is to have no file/folder changes to the host file system. Currently the .templateengine
folder is placed in the %USERPROFILE%
path on windows. I'm sure in similar places on other platforms. #9853 in the dotnet/cli
repo was opened to track this effort. @peterhuene mentioned that the DOTNET_CLI_HOME
variable available in 2.1.4xx
should keep things in a location of choice, e.g. a data/
folder on a usb drive.
Could this variable be used to also change where the .templateengine
folder is kept?
@jamiewest - Currently we don't support the DOTNET_CLI_HOME variable. There is a way built-in to dotnet new to cause it to create the .templateengine folder in a location of your choice. This is done using the "--debug:custom-hive <HivePath>" flag on the command line. For example:
dotnet new --debug:custom-hive c:\temp\example\MyHive
When dotnet new sees this flag, the specified HivePath is used instead of %USERPROFILE%\.templateengine
. If the HivePath doesn't exist, it's created, and will be setup just like the default .templateengine directory. Warning: If the HivePath does exist, but it doesn't contain the .firstrun
file, the contents will be overwritten (we should probably revisit this behavior, it can be a bit dangerous). Also note that when using --debug:custom-hive, we don't append .templateengine to the specified HivePath.
So, the first time a particular HivePath is encountered, initial setup is run. It's the same setup as when first running dotnet new without the custom hive, except the content goes to your chosen location. Then subsequent calls to dotnet new with the same --debug:custom-hive <HivePath> will use that already setup hive.
If you're creating something that will do its own command-line invocations of dotnet new, you can have that process inject the custom hive flag & value into the command line args for every call made to dotnet new. Otherwise the user would have to specify it every time - but if the hive path is ever mistyped, a new hive will be created in the mistyped location, which will probably lead to some confusion.
Alternately, if you're planning to use an API call into Microsoft.TemplateEngine.Cli, there is a constructor which takes the hivePath as an input parameter. Then whatever calls the API can always send in the same hivePath.
I'll give some consideration to having dotnet new honor the DOTNET_CLI_HOME variable for a future release.
+1 for supporting DOTNET_CLI_HOME. NuGet and other things bundled in the CLI support this.
cc @livarcocc @peterhuene
This issue was last touched some years ago. We are working on a new delivery road map. Please reopen if this is something we want & we'll properly assess its' priority compared to other work aimed at improving the overall templating UX.
This is surprising behavior when using docker.
@dotnet/templating-engine-maintainers let's retriage this issue, imo it makes sense considering other parties did it.
The fix for this issue (providing custom path for .templateengine folder) doesn't change the fact that there's a default location for ALL users, so #4275 is still relevant by itself.
The corresponding changes are CLI-specific - all changes have to be placed in sdk repo. Take a look at the example: https://github.com/dotnet/sdk/blob/3eea35e0d77f9a1bc418a364805ff89df818e371/src/Common/CliFolderPathCalculatorCore.cs
that can be used in https://github.com/dotnet/sdk/blob/3eea35e0d77f9a1bc418a364805ff89df818e371/src/Cli/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs#:~:text=%7D-,protected%20IEngineEnvironmentSettings%20CreateEnvironmentSettings(GlobalArgs%20args%2C%20ParseResult%20parseResult),-%7B
The issue was fixed for sdk 7.0.2xx version and now it is pending release.
Feel free to comment on this ticket if you have any questions.