Visual Studio:如何覆盖默认的“构建操作”对于每个项目或解决方案的某些扩展类型?

发布于 2024-09-10 19:30:44 字数 618 浏览 4 评论 0原文

我正在从许多程序集中提供我的 asp.net mvc 视图,并将视图复制到构建后事件的主应用程序。

然而,我意识到,这是有效的,当我更改视图中的某些内容并按下 F5 时,不会包含更改。要查看更改,我需要做的是:保存、构建<- 显式单击,然后按 F5。然而,这是一个非常烦人的解决方案。

我发现将视图上的“构建操作”设置为“嵌入式资源”也可以解决问题,但是其他开发人员可能不记得他们必须在将每个视图添加到解决方案后执行此操作。

有没有办法覆盖某些文件扩展名的默认构建操作,例如:项目中的 *.aspx、*.ascx 或(更好)解决方案中的?

我发现能够在每台机器上全局添加此设置,但我不想这样做(链接:http://blog.andreloker.de/post/2010/07/02/Visual- Studio-default-build-action-for-non-default-file-types.aspx

有什么想法吗?

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 ?

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

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

发布评论

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

评论(2

你又不是我 2024-09-17 19:30:44

考虑以下项目文件大纲:

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

这会将 Views\ 中的所有 aspxascx 文件添加到您的库中,作为 嵌入式资源。请注意,EmbedViews 添加到 DefaultTargets 之前 Build - 顺序在这里很重要,我发现自己犯了这个错误:-)

由于编辑所有项目文件来获取此代码片段很麻烦,因此您可以制作自己的项目模板并将其包含在内。

请告诉我这是否有帮助。

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.

木有鱼丸 2024-09-17 19:30:44

如果有人想知道 - 如果您希望它适用于当前未来项目,那么仍然无法做到这一点。

在 VS 2017 中,当存在包罗万象的规则(例如 Content Include = "**.*ts")时添加新文件时,如果添加新文件,它将添加自己的行
及其自己的 BuildAction,忽略您预定义的全部内容。

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.

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