Visual Studio:如何覆盖默认的“构建操作”对于每个项目或解决方案的某些扩展类型?
我正在从许多程序集中提供我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
考虑以下项目文件大纲:
这会将
Views\
中的所有aspx
和ascx
文件添加到您的库中,作为嵌入式资源
。请注意,EmbedViews
添加到DefaultTargets
之前Build
- 顺序在这里很重要,我发现自己犯了这个错误:-)由于编辑所有项目文件来获取此代码片段很麻烦,因此您可以制作自己的项目模板并将其包含在内。
请告诉我这是否有帮助。
Consider the following project file outline:
This will add all
aspx
andascx
files inViews\<subfolder>
to your library asEmbedded Resource
. Notice thatEmbedViews
is added toDefaultTargets
beforeBuild
- 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.
如果有人想知道 - 如果您希望它适用于当前和未来项目,那么仍然无法做到这一点。
在 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 ownBuildAction
, ignoring your predefined catch-all.