Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Visual Studio (2008) is there a way to have a custom dependent file on another custom file?

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.

like image 354
rball Avatar asked Apr 07 '09 22:04

rball


People also ask

How do I add files to VS project?

You can add existing files to your project by right-clicking on the Project node and selecting Add > Add Files.... Alternatively, to add an entire folder, select Add > Add Existing Folder.... The file browser is shown. It lets you search your system for the required item to add.


2 Answers

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.

like image 194
andrey.tsykunov Avatar answered Sep 25 '22 08:09

andrey.tsykunov


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>

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 displays it just as you'd expect it to.

like image 39
Jon Skeet Avatar answered Sep 26 '22 08:09

Jon Skeet