Conditionally embed ASP.NET MVC2 Views as resources during build in Visual Studio 2010

I have an ASP.NET MVC2 project in VS2010 that can be deployed in two modes: standalone or plugin. In standalone mode, views must be outside the compiled assembly as .aspx files (default setting). In plugin mode, views switch (currently manually) to embedded resources, and the entire assembly is deleted in the host project folder.

Currently, this requires the developer to go through each view and switch it from “Build actions”: “Content” to “Embedded resource” and vice versa. I would like to create a new solution configuration to automatically capture all .aspx files and create them as resources.

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

+4
source share
1 answer

Well, sometimes I have to experiment before publishing.

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

Views\*\*.aspx 

... and he did a great job. I posted a fragment of my reconfigured project file below. One note: adding a new view puts it in the “always content” category at the top of the snippet below. You can live with the presence of .aspx files even if the views are embedded as resources (not a problem for me), or you can move them from the first ItemGroup below to the "Other" section each time manually.

  <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> 
+3
source

Source: https://habr.com/ru/post/1307686/


All Articles