ligershark / sidewafflev2

Other
30 stars 11 forks source link

automatic replacements of tokens from replacementsDictionary #49

Closed avrahamcool closed 3 years ago

avrahamcool commented 3 years ago

Hi,

the projects that I have in my package have some information in them that I would like to be dynamically replaced at runtime. for instance: 1: I have a text containing the current year (currently hard coded) - and I want it to be replaced at runtime with the right year. 2: I have a place where i want to fill the current user name, instead of a hard-code one.

the replacementsDictionary has all of this information at runtime. ($year$, $username$). so I thought that if I would place $username$ in my project - it will be replaced automatically upon creation with the right data. but it just stays $username$.

I also thought that the symbols (http://json.schemastore.org/template) configuration may be what I need - but didn't found how to actually do it.

what is the right way of achiving this?

edit: I tried to follow the instruction here - https://docs.microsoft.com/en-us/visualstudio/ide/how-to-substitute-parameters-in-a-template?view=vs-2019 but the file that contains the data that I want to cahnge - is the .csproj of the project in the template. so his name is being replaced at run time. I'm not sure what should I put in the ProjectItem tag.

edit2: my template structure is complex - so maybe its a problem just for me? I have a vsix with multiple template inside. each template is a multiproject template. all the code is available here: https://github.com/avrahamcool/Aleph1.Skeletons

I would like to change this line from hard coded value to with $username$: https://github.com/avrahamcool/Aleph1.Skeletons/blob/1650c22215dd6413309423959f07a13d9d9d2a41/Aleph1.Skeletons.WebAPI/Aleph1.Skeletons.WebAPI.BL.Contracts/Aleph1.Skeletons.WebAPI.BL.Contracts.csproj#L6

sayedihashimi commented 3 years ago

@avrahamcool how invested are you in this current template? There is now a better, and much simpler, approach to creating templates. See my video series that was recently published over at https://youtube.com/playlist?list=PLqSOaIdv36hSx7WPUuFAVx59Ovbcpk_54

avrahamcool commented 3 years ago

@sayedihashimi first of all, thanks for the quick response - and the work you have done and shared.. you are a life saver.

I have invested a lot of time into creating/testing/adjusting the template to achieve this current state. so I was hoping to find an easy solution for the current problem that will not involve recreating the template from scratch.

but I'll watch the videos - and hopefully I'll learn more.

is this scenario not achievable with the current way of templating? I already have custom wizards defined - and I tweaked a lot of code to manipulate the solution before and after the template creation.. so it's not a big deal if I just need to tweak it a little more..

I'd be happy if you can give me some pointers..

sayedihashimi commented 3 years ago

Ok thanks no problem, I will certainly take a look. Do you have a sample that you can share with me to see if I can get it working?

avrahamcool commented 3 years ago

yes.. as I wrote in the question.. all of the code is published here: https://github.com/avrahamcool/Aleph1.Skeletons

and the goal is to replace the "hard coded" author name, with the current user who is initiating the template.

https://github.com/avrahamcool/Aleph1.Skeletons/blob/1650c22215dd6413309423959f07a13d9d9d2a41/Aleph1.Skeletons.WebAPI/Aleph1.Skeletons.WebAPI.BL.Contracts/Aleph1.Skeletons.WebAPI.BL.Contracts.csproj#L6

sayedihashimi commented 3 years ago

Thanks, I will take a look tomorrow.

sayedihashimi commented 3 years ago

@avrahamcool If I understand correct, you have a custom wizard and you want to replace the author name with a value that is specified by the user. Something very similar came up a while back, take a look https://github.com/ligershark/sidewafflev2/issues/17. In the comments there I have a sample that shows how to pass a parameter from your custom wizard through to the wizard that runs the code.

Let me know if that helps.

avrahamcool commented 3 years ago

@sayedihashimi again, thanks.

this is not exactly what I needed - the replacementsDictionary already contains the correct value at runtime (I don't need the user to specify it in a custom wizard). I just didn't find a way to "apply" the replacement automatically upon creation. if I simply use $username$ in my code - it just stays like that and not being replaced.

sayedihashimi commented 3 years ago

If you want the parameter to apply it will need to be prefixed with passthrough:, have you tried that?

replacementsDictionary.Add("passthrough:copyrightName", "value from wizard");

See

avrahamcool commented 3 years ago

Thanks. that did the trick.

I'm very grateful for your help.

sayedihashimi commented 3 years ago

@avrahamcool ok great, glad you got things working.