为视图添加为链接intellisense

编程入门 行业动态 更新时间:2024-10-27 18:26:09
本文介绍了为视图添加为链接intellisense的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用VS2015中的添加为链接"功能在项目中共享一些视图,但是即使在网站上运行正常,链接视图在VS中也会显示为损坏.

I'm trying to share some views across projects by using the "Add as Link" feature in VS2015 but the linked view appears broken in VS even though it works fine on the site.

是否有一种方法可以使智能感知和转到定义"等功能适用于链接的View?

我可以使用新的解决方案/项目来重现此内容:

I can reproduce this with a new solution/project:

  • 将Home/Index.cshtml移至其他文件夹(当前我正在使用解决方案"文件夹,但移动文件的位置似乎并不重要)
  • 从Home/删除Index.cshtml
  • 从主页/右键单击并添加现有项目"
  • 从解决方案文件夹中选择Index.cshtml,但从下拉菜单中选择添加为链接"
  • 在链接的Index.cshtml上选择属性复制到输出目录=始终复制"

该网站可以正常运行,但在VS2015中,该视图随后会出现损坏,并且没有智能感知.

The site will work fine but in VS2015 the view then appears broken and no intellisense works.

这将是在多个项目中共享视图的好方法,但是如果VS认为视图被破坏,则会使开发变得痛苦.

This would be a great way to share a view across multiple projects but if VS thinks the view is broken it makes developing a pain.

有什么建议吗?有没有更好的方法可以在项目之间共享视图?

Any suggestions? Is there a better way to share views across projects?

推荐答案

这是我让它工作的痛苦方式:

Here's the painful way I got it to work:

  • 卸载解决方案
  • 创建一个包含我要复制的视图的项目的副本.让我们将新项目称为[ SharedItems ].
  • 重命名.csproj文件并手动编辑.csproj文件,然后用新名称替换旧名称(可能是可选的,但使事情变得更容易)
  • 加载解决方案并添加新项目.
  • 删除不需要的任何文件.
  • 在新项目中重命名命名空间.
  • 进行构建以确保其正常工作并且Intellisense正常运行.
  • 删除要在原始项目中链接的文件并创建链接.
  • 在所有原始项目上安装了MSBuild.WebApplication.CopyContentLinkedFiles NuGet软件包,以自动制作链接文件的物理副本.
  • Unload the solution
  • Create a copy of one of the projects containing the views I want to replicate. Let's call the new project [SharedItems].
  • Rename the .csproj file and edit the .csproj file manually and replace the old name with the new name (probably optional, but made things easier)
  • Load the solution and add the new project.
  • Delete any files you don't need.
  • Rename the namespaces in the new project.
  • Build just to make sure it's working and Intellisense is working correctly.
  • Delete the files you intend to link in the original projects and create links.
  • Installed the MSBuild.WebApplication.CopyContentLinkedFiles NuGet package on all the original projects to automatically make physical copies of the linked files.
  • 现在,我可以在模板化项目中进行所有编辑,而不必到处维护多个副本.

    Now I can do all my edits in the templated project without having to maintain multiple copies everywhere.

    两个大缺点:

    • 我必须在对任何链接的对象进行编辑之后进行构建,然后才能看到所做的更改.
    • 我只需要在[ SharedItems ]项目中打开实际的.cshtml文件.打开链接的文件会中断Intellisense,直到您将其关闭并直接将其打开. Resharper的搜索无处不在"功能尤其令人讨厌,因为它建议链接的文件.
    • I have to build after making edits to any linked object before I can see the changes.
    • I have to open the actual .cshtml files in the [SharedItems] project only. Opening a linked file breaks Intellisense until you close it and open it directly. This is especially annoying with Resharper's Search Everywhere feature because it suggests linked files.

    更多推荐

    为视图添加为链接intellisense

    本文发布于:2023-11-15 17:41:57,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1596596.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:视图   链接   intellisense

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!