Visual Studio: How to override the default “Build Action” for certain extension types per project or solution?

前端 未结 2 1961
温柔的废话
温柔的废话 2021-01-18 02:27

I\'m serving my asp.net mvc views from many assemblies and copying views to the main application on post-build event.

This works, however, I realized, that when I ch

相关标签:
2条回答
  • 2021-01-18 02:53

    Consider the following project file outline:

    <Project ToolsVersion="3.5" DefaultTargets="EmbedViews;Build" ...>
    ...
      <Target Name="EmbedViews">
        <ItemGroup>
          <EmbeddedResource Include="Views\*\*.aspx" />
          <EmbeddedResource Include="Views\*\*.ascx" />
        </ItemGroup>
      </Target>
    </Project>
    

    This will add all aspx and ascx files in Views\<subfolder> to your library as Embedded Resource. Notice that EmbedViews is added to DefaultTargets before Build - order is important here, I found out making that mistake myself :-)

    Since editing all your project files to get this snippet in is cumbersome, you could make your own project template with this included.

    Please let me know if this helped.

    0 讨论(0)
  • 2021-01-18 02:57

    In case anyone wonders here - there is still no way to do that if you want it to work on current and future items.

    In VS 2017 when adding new file when the catch-all rule is present (e.g. Content Include = "**.*ts") if you add a new file, it will add it's own line to <ItemGroup> with it's own BuildAction, ignoring your predefined catch-all.

    0 讨论(0)
提交回复
热议问题