SharpDevelop Community

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

Modify *.csproj when *.doh-file is added

Last post 10-28-2007 4:23 PM by DanielGrunwald. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 10-06-2007 3:07 PM

    Modify *.csproj when *.doh-file is added

    Hi,

    I've written a binding to a declarative language called D'oh! that can work together with cs-files. At the moment I got some code completion and MSBuild integration. The problem I got now is that I need to manually  alter the csproj-file to get the MSBuild integration (adding a .targets and some code in '<Target Name="BeforeBuild">'). I guess I need to add some entry to "DohBinding.addin" that will trigger when .doh-files are added but that will alter the .csproj-file in the project. My question is how I will do this for #D3 (Laputa). I don't think any addin supplied is doing this at the moment so I don't know where to look for ideas. If you don't know the answer you can maybe point me in the right direction in the Laputa source code.

     

    Oscar Finnsson 

  • 10-06-2007 6:40 PM In reply to

    Re: Modify *.csproj when *.doh-file is added

    You can import a .targets file for all projects compiled by SharpDevelop by putting a string into /SharpDevelop/MSBuildEngine/AdditionalTargetFiles. This does not modify the .csproj file, so compilation of your language would only work inside SharpDevelop and not on the MSBuild command line.

    If you want to add an Imports node when a .doh file is added, you should handle ProjectService.ProjectItemAdded. Register an event handler using an autostart command:

        <Path name = "/Workspace/Autostart">
            <Class id = "MyAutostartCommand"
                   class = "MyNameSpace.MyAutostartCommand"/>
        </Path>

    In the event handler, check if the new item is a FileProjectItem, then check if the file extension is .doh and if the target project is a C# project. If yes, cast the project to MSBuildBasedProject, then do: lock (project.SyncRoot) { modify project.MSBuildProject; project.Save(); }

    Daniel Grunwald
  • 10-09-2007 3:08 PM In reply to

    Re: Modify *.csproj when *.doh-file is added

    Thanks for the answer. The addin is working now apart from some other problems that I will try to solve this week. I guess I'll post here again if I can't solve them :)

    Finnsson 

  • 10-20-2007 8:50 PM In reply to

    Modify *.csproj and add custom buildAction in xft

    Hi!

     

    I've been working on my D'oh!-binding today and solved most of my problems. The two problems I still got are:

    1. I would like my DohAutostartCommand : AbstractCommand to trigger not only when a .doh-file is added to a .csproj but also whenever I create a csproj with a doh-file (e.g. from a xpt-template).

    2. It seems like I can't have custom buildActions in xft-templates. At the moment I have this snippet of code in a xft-template:

    <File name="${FullName}.doh"  buildAction="Doh" language="DOH"> some code....

    However, the file is not assigned the element-name "Doh" in the csproj-file but instead assigned the element name "None". When I do this from a xpt-template it works just fine... .

    I'm writing the DohBinding for Laputa 3.0.0 build 2707.

     

    Apart from these two issues I got everything up and running. I get code completion in the cs-file, MSBuild-integration for doh-files with the right buildAction, etc. I've also got a small snippet of code that's automatically upgrading in csproj-file to c#/framework version 3.0/3.5 and setting the target CPU to x86 :)
     

    Take care,

    Finnsson
     

  • 10-20-2007 9:12 PM In reply to

    Re: Modify *.csproj and add custom buildAction in xft

    1. There doesn't seem to be a way for AddIns to tell the difference between adding an existing project to a solution and creating a new solution. I'll see if I can add some way for you to act on project creation when I implement choosing the target framework on project creation.

    2. I think buildAction should work in file templates, I'll test that later.


    BTW: SharpDevelop 3.0's code name is Montferrer; Laputa is the name of the team blog (don't ask me why the blog has a name...)

    Daniel Grunwald
  • 10-21-2007 9:15 AM In reply to

    Re: Modify *.csproj and add custom buildAction in xft

  • 10-21-2007 4:09 PM In reply to

    Re: Modify *.csproj and add custom buildAction in xft

    Regarding the buildAction:
     

    If I set the buildAction to "Doh" it shows up in the IDE as "Doh" (under Properties: Build Action), but in the csproj-file it's "None". If I save the solution and open it again it says "None" in the IDE too. It seems like the build action is somehow not transfered from the IDE to the csproj-file. The reason might be that you are using the Microsoft.Build.BuildEngine.Project-class directly since it seem to impose rules as to what tags are allowed.

    Just to clarity a bit I'm posting some source code from the csproj-file:

      <Doh Include="Window1.doh" />
      <None Include="Page1.doh" />

    Here "Page1.doh" got the wrong element type ("None"), since it should be "Doh".  

     

    Another observation is that if I change the build action to "Page" it will turn up as "None" in the csproj-file too, unless I change the file extension to ".xaml". The file extension seem to dictate what the permitted build actions are. 

  • 10-27-2007 5:00 PM In reply to

    Re: Modify *.csproj and add custom buildAction in xft

    I just tried adding a new file to a C# project. For the new file, I used this template:

    <?xml version="1.0"?>
    <Template>
        <Config
              name        = "D'oh"
              icon        = "C#.File.NewClass"
              category    = "C#"
              defaultname = "File${Number}.doh"
              language    = "Doh"/>
       
        <Description>A d'oh file</Description>
       
        <Files>
            <File name="${FullName}" buildAction="DohAction"><![CDATA[D'oh!]]></File>
        </Files>
    </Template>

     

    It got correctly added to the .csproj file as: <DohAction Include="File1.doh" />

    The MSBuild classes do not have any restrictions on the valid item group names. If you want to make "Doh" show up in the build action drop-down list in the properties pad, simply add this item group to your .targets file:

        <ItemGroup Condition="'$(BuildingInsideVisualStudio)'=='true'">
             <AvailableItemName Include="Doh" />
        </ItemGroup>

    Daniel Grunwald
  • 10-27-2007 5:11 PM In reply to

    Re: Modify *.csproj and add custom buildAction in xft

    I cannot reproduce the effect with "Page" either, I can set the build action of a .cs or .doh file to Page without any problems.

    I tried with SD 3.0.0.2730 on .NET 3.5 Beta 2. The project was a C# 3.0 project targeting .NET 2.0. I also tried it with an existing C# 2.0 project and got the same results.

    Daniel Grunwald
  • 10-28-2007 2:56 PM In reply to

    Re: Modify *.csproj and add custom buildAction in xft

    Thanks for the help. After some debugging I managed to pin-point the problem. It turned out that I had to set:

    file.BuildAction  = "Doh"

    in the DohCommand (AbstractCommand) where "file" is a FileProjectItem. The BuildAction was somehow set to "null" when I used the AbstractCommand on the FileProjectItem.

    I'm nearly ready to release the D'oh! declarative language now, but first I would like to fix two things:

    1. Is it possible to add custom code to a csproj-file (or any proj-file for that matter) from a xpt-file? If so I could make sure that the proj-file got the right version of MSBuild (3.5), link it to the correct targets and everything and I would not have to use an AbstractCommand for the case when I start from a new proj-file.

    2. Can I transfere error/warning-messages from my DohParser (IParser) to the IDE somehow? I got access to a CompilerErrorCollection from the DohParser and I think it would be nice if the user got instant feedback on syntax-errors in the IDE without having to recompile all the time.

    The first feature would be very good while the second would be more of a "nice to have".

     

    Take care,

    Finnsson 

  • 10-28-2007 4:23 PM In reply to

    Re: Modify *.csproj and add custom buildAction in xft

    1. Yesterday I modified SharpDevelop to always create new projects as MSBuild 3.5 projects (though an AddIn could reset a project to MSBuild 2.0).

    2. You can directly add errors/warning to the "Errors" pad by using ICSharpCode.SharpDevelop.TaskService.Add(). This will also underline them in the text editor. If you add lots of errors/warnings at once, set TaskService.InUpdate to true while you are adding them. Then the text editor will only redraw once when you set InUpdate back to false (otherwise it would redraw after each added error).

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