7

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 change something in view and just hit F5, changes are not included. What I have to do to see changes is to: save, build<- explicitly clicking, and then hit F5. However, it's pretty annoying solution.

I discovered that setting Build action to "Embedded Resource" on view solves the problem as well, however other devs may not remember that they have to do this after adding every view to the solution.

Is there a way to override the default build action for certain file extensions, such as: *.aspx, *.ascx in project or (better) in solution ?

What I've found is an ability to add this setting globally, per machine, but I do not want to do that (link: http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx)

Any ideas ?

tereško
  • 58,060
  • 25
  • 98
  • 150
Łukasz Podolak
  • 958
  • 3
  • 12
  • 24
  • 7
    You point to an article I mentioned in my post. Did you read my post or just scanned the title ? – Łukasz Podolak Sep 14 '10 at 14:21
  • The link is dead, archived version: https://web.archive.org/web/20100705150307/http://blog.andreloker.de/post/2010/07/02/Visual-Studio-default-build-action-for-non-default-file-types.aspx – Heki Dec 03 '18 at 09:32

2 Answers2

6

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.

Jeroen
  • 1,246
  • 11
  • 23
1

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.

sztrzask
  • 119
  • 11