views:

286

answers:

1

I have a ASP.NET MVC2 project in VS2010 that can be deployed in two modes: standalone or plugin. In standalone mode, the views should live outside the compiled assembly as .aspx files (the default setup). In plugin mode, the views are switched (currently by hand) to embedded resources and the entire assembly is dropped into a host project folder.

Currently, this requires the developer to go through each view and switch it from Build Action: "Content" to "Embedded Resource" and vice versa. I would like to create a new solution configuration to automatically grab all .aspx files and build them as resources.

This SO post seems like the solution, but I would prefer not to have to edit the .csproj every single time I add a new view to the project. Is there a way to use a wild cards or some other batch/global conditionally statement to change resources from content to embedded?

+2  A: 

Well, sometimes I should experiment before I post.

I modified my .csproj file and just went ahead and tried a wild card:

Views\*\*.aspx

...and it worked great. I posted a snippet of my reconfigured project file below. One thing to note: adding a new view puts it in the "always content" category at the top of the snippet below. You can either live with having .aspx files deployed even when the views are embedded as resources (not an issue for me) or you can move them from the first ItemGroup below to the Otherwise section each time by hand.

 <ItemGroup>                              <-- Always included as content
    <Content Include="Global.asax" />
    <Content Include="Web.config">
      <SubType>Designer</SubType>
    </Content>
    <Content Include="Web.Debug.config">
      <DependentUpon>Web.config</DependentUpon>
    </Content>
    <Content Include="Web.Release.config">
      <DependentUpon>Web.config</DependentUpon>
    </Content>
  </ItemGroup>
<Choose>                             <--- Only added to assembly in "Plugin Mode"
    <When Condition=" '$(Configuration)'=='Plugin' ">
      <ItemGroup>                  
        <EmbeddedResource Include="Views\*\*.aspx">
        </EmbeddedResource>
      </ItemGroup>
    </When>
    <Otherwise>
      <ItemGroup>
        <Content Include="Views\Comment\Create.aspx" />
        <Content Include="Views\Record\Create.aspx" />
      </ItemGroup>
    </Otherwise>
  </Choose>
jslatts