views:

565

answers:

2

Hi,

My issue is copying *.cs files to my project using my own code generator program (like hibernate) So when my code generator program creates new .cs class I want it to be copied to project path and see it via VS2008 solution explorer.

(Note: Normally you can copy files to project folder but VS2008 doesn't see it since you didn't use VS2008 interface)

Thanks for your brilliant answers.

A: 

To add files to the project, you'll have to parse and modify the C# project (.csproj) file. You need to add tags for:

<ItemGroup>
  <Content Include="MyNewFile.cs">
    <SubType>Code</SubType>
  </Content>
</ItemGroup>

See your existing .csproj file for more examples of files you can add.

kdmurray
Thanks it works. for those using VS2008. The syntax below is valid<ItemGroup> <Compile Include="DB\DBAccessLevels.cs" /></ItemGroup>
James Lee
A: 

If you bust open the .vcproj file in notepad, you'll see something like this:

<Files>
 <Filter
  Name="Source Files"
  Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
  UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
  >
  <File
   RelativePath=".\foo.cpp"
   >
  </File>

You need to use your favorite XML parsing API to add more elements.

EDIT:

For a .csproj, add more elements like this:

<Compile Include="foo.cs" />
jeffamaphone

related questions