Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top