Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual Studio custom project template with multiple projects
    primarykey
    data
    text
    <p>I am trying to write some custom project templates for my team so we can be consistent on creation of new modules for our application, also to make it easier to create new modules. I mostly have it working but I am having issues adding the project references.</p> <p>I am aiming for a project structure like this:</p> <pre><code>/Root /Modules /ModuleName /ModuleName.Interface /ModuleName.ViewModels /ModuleName.Views </code></pre> <p>The ModuleName project has project references to all of them, the ModuleName.Views project has a reference to the ModuleName.Interface and ModuleName.ViewModels projects. So I have setup all the vstemplate files, all the projects generate correctly except for the project references.</p> <p>I have this defined in my main vstemplate for the module:</p> <pre><code>&lt;TemplateContent&gt; &lt;ProjectCollection&gt; &lt;ProjectTemplateLink ProjectName="$safeprojectname$.Interface"&gt;Module.Interface\Module.Interface.vstemplate&lt;/ProjectTemplateLink&gt; &lt;ProjectTemplateLink ProjectName="$safeprojectname$"&gt;Module\Module.vstemplate&lt;/ProjectTemplateLink&gt; &lt;ProjectTemplateLink ProjectName="$safeprojectname$.ViewModels"&gt;Module.ViewModels\Module.ViewModels.vstemplate&lt;/ProjectTemplateLink&gt; &lt;ProjectTemplateLink ProjectName="$safeprojectname$.Views"&gt;Module.Views\Module.Views.vstemplate&lt;/ProjectTemplateLink&gt; &lt;/ProjectCollection&gt; &lt;/TemplateContent&gt; </code></pre> <p>I have this defined in my Module.Views.vstemplate file:</p> <pre><code>&lt;Project File="Module.Views.csproj" TargetFileName="$safeprojectname$.Views.csproj" ReplaceParameters="true"&gt; &lt;ProjectItem TargetFileName="packages.config" ReplaceParameters="false"&gt;packages.config&lt;/ProjectItem&gt; &lt;ProjectItem TargetFileName="assemblyinfo.cs" ReplaceParameters="true"&gt;properties\assemblyinfo.cs&lt;/ProjectItem&gt; &lt;/Project&gt; </code></pre> <p>Then I have this defined in my Module.Views.csproj file:</p> <pre><code>&lt;ItemGroup&gt; &lt;ProjectReference Include="..\$safeprojectname$.Interface\$safeprojectname$.Interface.csproj"&gt; &lt;Project&gt;{4f6aa0f2-a984-43c3-8fad-7e2f00351f7e}&lt;/Project&gt; &lt;Name&gt;$safeprojectname$.Interface&lt;/Name&gt; &lt;/ProjectReference&gt; &lt;ProjectReference Include="..\$safeprojectname$.ViewModels\$safeprojectname$.ViewModels.csproj"&gt; &lt;Project&gt;{e5a562f9-58b2-4ab5-bb9d-8dc806322e62}&lt;/Project&gt; &lt;Name&gt;$safeprojectname$.ViewModels&lt;/Name&gt; &lt;/ProjectReference&gt; &lt;/ItemGroup&gt; </code></pre> <p>It correctly names all of the projects but my project references end up like this:</p> <pre><code>ModuleName.Views.Interface ModuleName.Views.ViewModels </code></pre> <p>It looks like the $safeprojectname$ macro behaves differently when it is applied in a vstemplate and a csproj file. It seems that when it is processing vstemplate files $safeprojectname$ is the name of the project that you entered when prompted by the IDE but in the csproj files $safeprojectname$ is the expanded project name specific to that vstemplate, e.g. ModuleName.Views when I was expecting it to be ModuleName.</p> <p>I tried to use CustomParameters but they seem to be deferred until that last minute, e.g.:</p> <pre><code>&lt;CustomParameters&gt; &lt;CustomParameter Name="$ModuleInterfaceProjectName$" Value="$safeprojectname$.Interface"/&gt; &lt;CustomParameter Name="$ModuleProjectName$" Value="$safeprojectname$"/&gt; &lt;CustomParameter Name="$ModuleViewModelsProjectName$" Value="$safeprojectname$.ViewModels"/&gt; &lt;CustomParameter Name="$ModuleViewsProjectName$" Value="$safeprojectname$.Views"/&gt; &lt;/CustomParameters&gt; </code></pre> <p>This results in the same reference to ModuleName.Views.Interface.</p> <p>Does anyone know how to get around this behavior? I know I can write a custom wizard to fix this but I was hoping to not go that far.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload