admin管理员组文章数量:1245895
I have created a solution in Visual Studio and I have the solution in a good place now to create a template that I can use for future projects. I have added ApplicationDbContext with Identity and seeded users and roles. I have implemented role and permission based auth. I have configured JWT and Cookie Auth, and have an AuthController, etc.
I have exported my projects using the template export wizard and have added a vstemplate file that references the project vstemplate files correctly.
I can open VS and create a new solution based on my exported template, and it creates the solution almost correctly. One issue that I am seeing is that it doesn't replace the namespaces in my Client project GlobalUsings.cs file that are Common Project namespaces.
Client Project Global Usings
global using JwtIdentity.Client.Services.Base;
global using JwtIdentity.Common.Auth;
global using JwtIdentity.Common.Helpers;
global using JwtIdentity.Common.ViewModels;
When I create a new solution using a template based on this, JwtIdentity should be replaced with whatever I choose as the name of the solution when creating it.
In the exported template, I have
global using $safeprojectname$.Services.Base;
global using $safeprojectname$.Common.Auth;
global using $safeprojectname$.Common.Helpers;
global using $safeprojectname$.Common.ViewModels;
$safeprojectname$
evaluates to BlazorSolution1.Client, if I set the solution name to BlazorSolution1, which is correct for the first using because Services.Base is in the Client project.
I have tried different things such as $defaultnamespace$
and $rootnamespace$
. I have Googled and looked at lots of Youtube videos, but I can't find anything that specifically addresses this issue.
Here is my multi-project template.
<VSTemplate Version="2.0.0" Type="ProjectGroup" xmlns=";>
<TemplateData>
<Name>Complete Blazor Solution Template</Name>
<Description>A template for a Blazor solution with identity, roles, permissions, JWT and Cookie auth. Includes Login pages, Logout, Register, Email Verification on Register, Swagger, Mudblazor framework, light and dark mode switcher, responsive GUI design, etc.</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>Blazor</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>BlazorSolution</DefaultName>
</TemplateData>
<TemplateContent>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$safeprojectname$" CopyParameters="true">CompleteBlazorProject\MyTemplate.vstemplate</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Client" CopyParameters="true">CompleteClientProject\MyTemplate.vstemplate</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Common" CopyParameters="true">CompleteCommonProject\MyTemplate.vstemplate</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
And part of my Client template
<VSTemplate Version="3.0.0" xmlns="; Type="Project">
<TemplateData>
<Name>Complete Client Project</Name>
<Description>This is a Complete Client Project</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>Complete Client Project</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<CreateInPlace>true</CreateInPlace>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="JwtIdentity.Client.csproj" File="JwtIdentity.Client.csproj" ReplaceParameters="true">
<Folder Name="wwwroot" TargetFolderName="wwwroot">
<ProjectItem ReplaceParameters="true" TargetFileName="appsettings.json">appsettings.json</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="appsettings.Development.json">appsettings.Development.json</ProjectItem>
</Folder>
...
<ProjectItem ReplaceParameters="false" TargetFileName="_Imports.razor">_Imports.razor</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="GlobalUsings.cs">GlobalUsings.cs</ProjectItem>
<ProjectItem ReplaceParameters="true" TargetFileName="Program.cs">Program.cs</ProjectItem>
<ProjectItem ReplaceParameters="false" TargetFileName="Routes.razor">Routes.razor</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate>
And part of my Common project template
<VSTemplate Version="3.0.0" xmlns="; Type="Project">
<TemplateData>
<Hidden>true</Hidden>
<Name>Complete Common Project</Name>
<Description>This is a complete common project</Description>
<ProjectType>CSharp</ProjectType>
<ProjectSubType>
</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>Complete Common Project</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
<CreateInPlace>true</CreateInPlace>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<Project TargetFileName="JwtIdentity.Common.csproj" File="JwtIdentity.Common.csproj" ReplaceParameters="true">
...
<ProjectItem ReplaceParameters="true" TargetFileName="GlobalUsings.cs">GlobalUsings.cs</ProjectItem>
</Project>
</TemplateContent>
</VSTemplate>
I'm sure there is an easy way to replace external project usings, but I am not sure what I am doing wrong. Any help would be appreciated.
本文标签:
版权声明:本文标题:namespaces - Replacing Referenced Project Usings Using Visual Studio Templates in Multi Project Solution Not Working - Stack Ove 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740225094a2244537.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论