在 Visual Studio 2010 中构建期间有条件地将 ASP.NET MVC2 视图嵌入为资源

发布于 2024-08-29 12:07:24 字数 453 浏览 2 评论 0原文

我在VS2010中有一个ASP.NET MVC2项目,可以以两种模式部署:独立模式或插件模式。在独立模式下,视图应作为 .aspx 文件存在于已编译的程序集外部(默认设置)。在插件模式下,视图(当前是手动)切换到嵌入资源,并将整个程序集放入主机项目文件夹中。

目前,这需要开发人员浏览每个视图并将其从构建操作:“内容”切换到“嵌入式资源”,反之亦然。我想创建一个新的解决方案配置来自动抓取所有 .aspx 文件并将它们构建为资源。

这个 SO post 似乎是解决方案,但我更喜欢每次向项目添加新视图时都不必编辑 .csproj。 有没有办法使用通配符或其他批处理/全局条件语句将资源从内容更改为嵌入?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷不放纵 2024-09-05 12:07:24

好吧,有时我应该在发帖之前进行实验。

我修改了 .csproj 文件,然后继续尝试使用通配符:

Views\*\*.aspx

...并且效果很好。我在下面发布了重新配置的项目文件的片段。需要注意的一件事:添加新视图会将其置于下面代码片段顶部的“始终内容”类别中。即使视图作为资源嵌入(对我来说不是问题),您也可以接受部署 .aspx 文件,或者您可以每次手动将它们从下面的第一个 ItemGroup 移至“其他”部分。

 <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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文