Visual Studio Custom Item Template Dependent Upon
Asked Answered
L

2

8

I'm writing my own custom item template for use within visual studio. All is well except I need to find a way to get one of the files in the template to be dependent upon another.

In a csproj file it would look like this

<Compile Include="Class1.cs">
    <DependentUpon>Class1.xml</DependentUpon>
</Compile>

Does anybody have any idea how I would define this in the vstemplate file?

Thanks

Leafage answered 11/11, 2010 at 12:31 Comment(3)
How did you solve this? I flagged this question for reopening because the duplicate actually isn't a duplicate, its another question.Gilges
Agree this is not a duplicate. This is about Item Templates, not just editing .proj files (as the other question relates to)Nor
Please select the answer. the answer by @Yasin Kilicdere worked for me.Branen
O
17
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs" ReplaceParameters="true">Test.cs</ProjectItem>
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.cs\$fileinputname$Dependent.cs" ReplaceParameters="true">TestDependent.cs</ProjectItem>
Ovariectomy answered 4/3, 2013 at 14:22 Comment(4)
This answer wasn't selected as correct but I have tested it in VS2012 and it DOES work...Gondar
I tested in VS2012 it DOES work. It's the most simple and correct way.Mirabelle
Works on VS 2017 tooFerd
Note that this behavior was apparently not officially supported and no longer works in VS 16.5Dolt
C
0

Not sure if this can happen automatically for non-managed file types (i.e. file types that VS doesn't know about, like yours)...

A hack would be to use WizardExtensions (google for examples on writing a basic wizard) like this:

  • Add the files initially as .cs and .designer.cs.
  • Then use wizardExtensions to rename those files

or

  • see if wizard extensions can directly modify the csproj (but that be difficult as VS might not let you do that without unloading the project first).

hope this helps...

Cascade answered 19/1, 2011 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.