locked
How to dynamically include .cs files in a .csproj on build time RRS feed

  • Question

  • Hi,

    I  have the following scenario: I have a C# project that is build as a DLL and a script that generates on build time, some .cs files from some xml-s. I want to dynamically include that generated .cs files into the C# dll project and then build the project to provide those generated classes into the DLL file. 
     
    Thanks,
    Feroiu Laurentiu
    Friday, February 26, 2010 4:24 PM

Answers

  • Hi, Feroiu

    What is the Script you used? How it could it be ran in your code? If so I think we could  use BuildEventsClass.OnBuildBegin Event. This event was triggered before your build start.

    Here is the sample code.

                        BuildEvents be = _applicationObject.Events.BuildEvents;

                        be.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(be_OnBuildBegin);

            void be_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)

            {

     

                    //Run you script here

     

                    _applicationObject.Solution.Projects.Item(1).ProjectItems.AddFromFileCopy(@"D:\Class1.cs");

     

            }

    If you have anything unclear, feel free to let me know.

    Thanks

    Chao

    • Proposed as answer by Carlos J. Quintero Wednesday, March 3, 2010 9:07 AM
    • Marked as answer by Chao Kuo Friday, March 5, 2010 5:55 AM
    Tuesday, March 2, 2010 12:11 PM