2

In a web project, when I right click on the project or a folder, I get Add -> New Scaffolded Item as an option. However, when trying this in a Class Library project, the option is not there. Right now, I'm adding the item in my web project and moving it to my class library.

Is there any way to add a "Scaffolded Item" to a class library (or any non-web project for that matter)?

Chad Schouggins
  • 3,440
  • 2
  • 23
  • 29

1 Answers1

1

One possibility is to trick Visual Visual Studio into thinking that your class library is an ASP.NET MVC application. For example in VS 2013 and ASP.NET MVC 5 you could open your class library .csproj file in your favorite text editor (notepad.exe in my case) and add the following just after the <ProjectGuid> tag:

<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>

and replace:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

with:

<PropertyGroup>
  <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
  <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

Now reload your solution in Visual Studio and you will be find some new context menus when you right click on your class library project.

But to be honest, why would you wanna rely on some magic to write the code for you instead of writing it yourself?

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928