问题描述
我想要一个 *.js 文件,而不是后面或旁边的 *.cs 代码.我正在开发一个 MVC 应用程序,不需要旁边的代码,因为我有控制器,但在某些情况下,旁边有一个 JavaScript 代码或某种方式将文件关联到它正在使用的页面会很好.我想我可以给它们起类似的名字,但如果可能的话,我想显示关联,这样就不会对文件的用途产生疑问.
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.
通常,我现在谈论的是在 Visual Studio 中的 Global.asax 文件下,您将在左侧有一个加号:
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
更新:
我现有的 csproj 文件有一个指向实际文件的路径,不确定这是否搞砸了.我目前有:
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="ViewsUserProfile.spark.js">
<DependentUpon>ViewsUserProfile.spark</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="ViewsUserProfile.spark" />
</ItemGroup>
它只是显示彼此旁边的文件.
and it's simply just showing the files besides each other.
推荐答案
当然可以 - 但您必须手动编辑项目文件.找到您的子"文件条目,并将其更改为非自关闭元素,并添加一个子元素来说明它所依赖的内容.以下是正在编译的 .cs 文件的示例:
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:
<Compile Include="AssertCount.cs">
<DependentUpon>MoreEnumerable.cs</DependentUpon>
</Compile>
这是我刚刚为您指定的文件模拟的一个版本 - 尽管我希望 Home.spark
将有一个与之关联的操作而不是无":
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":
<ItemGroup>
<Content Include="Home.spark.js">
<DependentUpon>Home.spark</DependentUpon>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="Home.spark" />
</ItemGroup>
Visual Studio 会按照您的预期显示它.
Visual Studio displays it just as you'd expect it to.
这篇关于在 Visual Studio (2008) 中,有没有办法在另一个自定义文件上创建自定义依赖文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!