Frage

I'm creating a project template for an MVC 4 starter project.

In any normal class based code file, I can write the following syntax for visual studio to fill in this $safeprojectname$ wildcard with the project name originally given by the user when creating a new project.

namespace $safeprojectname$.Models
{
    public class Class1
    {     
        public bool blah { get; set; }
    }
} 

however my issue is that, for any view file (*.cshtml) these template wildcards simply do not get evaluated. So instead of being replaced, the wildcard raw text persists into the markup, which in turn bombs the preprocessor logic when running the project.

an example of what the view file code looks like.

@model $safeprojectname$.Models.NavigationBarModel

Are there any solutions for this?

War es hilfreich?

Lösung

I eventually figured this out along with a few other gotchas.

the .vstemplate file that gets generated creates a <ProjectItem> element for each resource included in your exported template.

the ReplaceParameters attribute needs to manually be set to true for views by default it is set it was false.

<Folder Name="Shared" TargetFolderName="Shared">
  <ProjectItem ReplaceParameters="true" TargetFileName="_Layout.cshtml">_Layout.cshtml</ProjectItem>
  <ProjectItem ReplaceParameters="true" TargetFileName="_LoginPartial.cshtml">_LoginPartial.cshtml</ProjectItem>
  <ProjectItem ReplaceParameters="true" TargetFileName="_NavigationBar.cshtml">_NavigationBar.cshtml</ProjectItem>
  <ProjectItem ReplaceParameters="true" TargetFileName="Error.cshtml">Error.cshtml</ProjectItem>
</Folder>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top