SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

How to add a file to an AbstractProject that is not MSBuild-based?

Last post 11-18-2014 5:10 PM by chrish. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 10-16-2014 5:18 PM

    • chrish
    • Not Ranked
    • Joined on 10-16-2014
    • Posts 5

    How to add a file to an AbstractProject that is not MSBuild-based?

    Hi all,

    first of all thank you for creating this project. I love where it's heading.

    I searched but found nothing about this. If this question has been answered already, you may notify here and close this thread.

    I'm currently writing an add-in for a custom language that is not MSBuild-based, thus I'm deriving from AbstractProject since that has everything I needed. When it builds, it just calls some EXE that does the compilation - no need for MSBuild. But that is not the problem.

    You can basically compare the language to VB6 where you have a bunch of files that are organized by category (Modules, Classes, Forms). Essentially I want to recreate that, since that layout is efficient for the language.

    I'm loading the project file inside the appropriate constructor, and when I try to call ProjectService.AddProjectItem(), it gives me a NotSupportedException. So, is this even the correct approach? Where is it best to do the "stuffing into the project tree"?

    I'm using the RC of SD (downloaded 14th of October).

    I'd be glad for any sort of heads-up on this.


    Best Regards,

    chris

    Filed under:
  • 10-16-2014 7:48 PM In reply to

    Re: How to add a file to an AbstractProject that is not MSBuild-based?

    In SharpDevelop 5.x, ProjectService.AddProjectItem() is just a left-over method from older SharpDevelop versions where this was necessary in order to raise the ProjectItemAdded event. In SharpDevelop 5.x, the method is simply implemented as: project.Items.Add(item);, and the project's ItemCollection is instead responsible for calling IProjectServiceRaiseEvents.RaiseProjectItemAdded(), so ProjectService.AddProjectItem() now is no longer necessary.

    So to support adding items to your project, you need to implement IProject.Items and return an appropriate collection. You will need to implement the IMutableModelCollection interface yourself for this purpose, as none of the public implementations in SharpDevelop are appropriate for this purpose: the collection must be thread-safe (synchronized with project's SyncRoot), and raise not only its own CollectionChanged event, but also the global project service events via IProjectServiceRaiseEvents. Take a look at the MSBuildBasedProject.ProjectItemCollection in the SharpDevelop source code, it's the only example we have.

  • 10-17-2014 9:19 PM In reply to

    • chrish
    • Not Ranked
    • Joined on 10-16-2014
    • Posts 5

    Re: How to add a file to an AbstractProject that is not MSBuild-based?

    Hey Daniel,

     

    Thank You for your help! It was just what I needed. 

     

    However, I couldn't yet figure out how to tell SD that I want it to have "virtual" folders in the project, like this:

    http://msdn.microsoft.com/en-us/library/aa232712(v=vs.60).aspx

     

    (The "Forms" folder doesn't really exist and it is just a logical grouping of the files, like the "References" pseudo-folder)

     

     

    Can you tell me if this is possible with SD? If not, then it's not a big problem for me however. It doesn't have to work at all costs.

     

    Thanks so far and Best Regards,

    chris

     

    EDIT: Now I can tell. This is for my add-in (see here on the forums). I just don't want to talk about chickens that aren't hatched.

  • 10-18-2014 12:12 AM In reply to

    Re: How to add a file to an AbstractProject that is not MSBuild-based?

    You can implement IProjectNodeBuilder to provide a custom TreeNode for your project. The F# and WiX bindings already use this for some slight adjustments to the project explorer (in F#, the order of the files within the project matters, and WiX has some additional virtual folders like WiX extensions and WiX libraries)

    In the .addin file, the usage is like this:

        <Path name = "/SharpDevelop/Views/ProjectBrowser/NodeBuilders">
            <Class id = "WixProjectBuilder"
                   insertbefore = "DefaultBuilder"
                   class = "ICSharpCode.WixBinding.WixProjectNodeBuilder"/>
        </Path>

    See the SharpDevelop source code for the implementation of the class.

  • 11-18-2014 5:10 PM In reply to

    • chrish
    • Not Ranked
    • Joined on 10-16-2014
    • Posts 5

    Re: How to add a file to an AbstractProject that is not MSBuild-based?

    Hey Daniel,

    Thanks, that was exactly what I needed. Although meanwhile I'm not quite sure whether it is worth the investment currently - the solution explorer looks good enough for what it is ;)

     

    I will keep it in mind just in case I should need it.

     

    Best Regards,

    chris

Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this (fleischfalle@alphasierrapapa.com) email address.