在 Visual Studio (2008) 中,有没有办法在另一个自定义文件上创建自定义依赖文件?
我想要一个 *.js 文件,而不是后面或旁边的 *.cs 代码。 我正在开发一个 MVC 应用程序,不需要额外的代码,因为我有控制器,但在某些情况下,最好在旁边有一个 JavaScript 代码,或者通过某种方式将文件关联到正在使用的页面。 我想我可以以类似的方式命名它们,但如果可能的话,我想显示关联,这样就不会有文件用途的问题。
通常,我现在所说的是在 Visual Studio 中的 Global.asax 文件下,左侧会有一个加号:
+ Global.asax
一旦展开它,您就会得到
- Global.asax
Global.asax.cs
我希望发生同样的事情:
+ Home.spark
- Home.spark
Home.spark.js
已更新:
我现有的 csproj 文件有一个实际文件的路径,不确定这是否会搞砸。 我目前已经得到:
<ItemGroup>
<Content Include="Views\User\Profile.spark.js">
<DependentUpon>Views\User\Profile.spark</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Views\User\Profile.spark" />
</ItemGroup>
并且它只是仅显示彼此旁边的文件。
Instead of a *.cs code behind or beside I'd like to have a *.js file. I'm developing a MVC application an have no need for a code beside because I have controllers, but in certain cases it'd be nice to have a JavaScript code beside or some way to associate the file to the page it's being used on. I suppose I could just name them similarly, but I'm wanting to show the association if possible so there's no question about what the file is for.
Typically what I'm talking about is within Visual Studio now under your Global.asax file you will have a plus sign to the left:
+ Global.asax
Once you expand it you'll get
- Global.asax
Global.asax.cs
I'd like the same thing to happen:
+ Home.spark
- Home.spark
Home.spark.js
Updated:
My existing csproj file has a path to the actual file, not sure if that's screwing it up. I've currently got:
<ItemGroup>
<Content Include="Views\User\Profile.spark.js">
<DependentUpon>Views\User\Profile.spark</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="Views\User\Profile.spark" />
</ItemGroup>
and it's simply just showing the files besides each other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
有 VSCommands 插件,允许您直接从
更新的 IDE 链接配置依赖文件,以前是 http://mokosh.co.uk/vscommands
仅供参考:安装 VSCommands 后,只需选择您想要依赖的所有文件和根文件,然后右键单击 -> Group Items... 和 VSCommands 将询问您希望哪个文件成为根文件。
There is VSCommands add-in which allow you to configure dependant files directly from IDE
Link updated, previous was http://mokosh.co.uk/vscommands
FYI: When VSCommands is installed, just select all the files you want to be Dependant and the root file, then Right Click -> Group Items... and VSCommands will ask which of the files you would like to be the root file.
绝对可以 - 但您必须手动编辑项目文件。 找到“子”文件的条目,并将其更改为非自关闭元素,然后添加一个子元素来说明它所依赖的内容。 这是正在编译的 .cs 文件的示例:
这是我刚刚为您指定的文件模拟的版本 - 尽管我预计
Home.spark
将有一个与其关联的操作比“无”:Visual Studio 按照您的预期显示它。
Absolutely - but you'll have to edit the project file by hand. Find your "child" file's entry, and change it to be a non-self-closing element, and add a child element to say what it depends on. Here's an example for a .cs file being compiled:
And here's a version I've just mocked up for the files you've specified - although I expect
Home.spark
will have an action associated with it rather than "None":Visual Studio displays it just as you'd expect it to.
我不知道如何通过 Visual Studio UI 本身来完成此操作,但如果您在文本编辑器中打开 csproj 文件,您可以看到他们如何为 Global.asax 执行此操作。
它通常看起来像这样:
I don't know how you can do it via the Visual Studio UI itself, but if you open the csproj file in a text editor, you can see how they do it for Global.asax.
It usually looks something like this:
虽然此处的其他解决方案(编辑项目文件)适用于单个文件,但我们做了同样的事情,但希望它自动适用于所有 *.conv 和 *.conv.js 文件,而不必编辑项目文件为每一个。
当我们向应用程序添加新的 .conv 文件时,如果我们有一个 *.conv.js 文件,它会自动嵌套在它下面,就像您对 .aspx 和 *.aspx.cs 的期望一样。
我找不到我用来设置这个的原始教程(它确实涉及注册表黑客),但这是我刚刚从 Google 搜索中发现的一个描述相同内容的教程
: dotnetwise.com/2009/09/visual-studio-2008-custom-nested-files.html" rel="nofollow noreferrer">http://blog.dotnetwise.com/2009/09/visual-studio-2008-custom -nested-files.html
Whilst the other solutions here (editing the project file) work for individual files, we've done the same thing, but want it to work automagically for all *.conv and *.conv.js files rather than having to edit the project file for each one.
When we add a new .conv file to our app, if we have a *.conv.js file it automatically nests under it as you'd expect with .aspx and *.aspx.cs.
I can't find the original tutorial I used to set this up (it does involved registry hacking) but here is one I found from a Google search just now that describes the same thing:
http://blog.dotnetwise.com/2009/09/visual-studio-2008-custom-nested-files.html
如果您需要为某些文件添加代码隐藏,有一个解决方法。 例如,您希望将 Test.xaml.cs 设为 Test.xaml 的子级。 完成以下步骤:
从项目中排除 Test.xaml 和 Test.xaml.cs,保存项目。
卸载项目。
重新加载项目。
在文件资源管理器窗格中单击“显示隐藏文件”。
文件Test.xaml.cs将显示为Test.xaml的子级。
将文件添加回项目,保存项目。
就是这样。 现在Test.xaml.cs依赖于Test.xaml。
If you need to add code-behind for some file there is a workaround. For instance you want to make Test.xaml.cs a child of Test.xaml. Complete the following steps:
Exclude both Test.xaml and Test.xaml.cs from project, save project.
Unload project.
Reload project.
Click "Show hidden files" in File Explorer pane.
File Test.xaml.cs will be displayed as child of Test.xaml.
Add files back to project, save project.
That's it. Now Test.xaml.cs is dependent on Test.xaml.
John Skeed 建议您可以手动编辑项目文件,或者您也可以查看 适用于 Visual Studio 的文件嵌套扩展 将为您完成这项工作。
You can edit by hand the project file, has John Skeed suggested, or you can also have a look on the File Nesting Extension for Visual Studio that will do the job for you.