0

I'm building a winforms plug-in project with visual Studio 2013 Express. It will be a 'toolbox' where various 'tools' can be added by copying their DLLs to some folder from where they can be seen, loaded and added on a new tabpage. I have decided to run one VS copy for the plug-in frame and one to create the plug-ins.

I have found this thread on how to create DLLs from a studio project and for the first test everything went fine. Nice workflow. But when I changed the first tool to descend not directly form UserControl but from a custom plug-in base class which inherits from UserControl I got a compiler error. (type or namespace 'Base' not found...)

Here is a totally stripped-down version, which will get the same error. Obviously there is something wrong or missing in the edited .csproj file.

  • So, how should the build file be changed to allow creating DLLs for inherited classes?
  • Also: Is there an explanation of the options, like "Plugin" or "DependentUpon" or "SubType" ?
  • BTW: In the real version I had to merge the partial class parts of the UserControl to make it work. (That was before moving to the base class.) Can I change the .csproj file to allow partial classes?

     
        using System;
        //..
        namespace test_cx1
        {
            class Base
            {
            }
        }
    
    using System;
    //..
    
    namespace test_cx1
    {
        class Tool1 : Base
        {
        }
    }
    
    
    <ItemGroup>
       <Compile Include="Base.cs">
          <Plugin>true</Plugin>
       </Compile>
       <Compile Include="Tool1.cs">
         <Plugin>true</Plugin>   <!-- does not compile -->
       </Compile>    
    ..
    ..
    <Target Name="BuildPlugins">
        <CSC Condition="%(Compile.Plugin) == 'true'" 
    Sources="%(Compile.FullPath)" 
    TargetType="library" 
    OutputAssembly="$(OutputPath)%(Compile.FileName).dll" 
    EmitDebugInformation="true" />
    </Target>
    <Target Name="AfterBuild" DependsOnTargets="BuildPlugins">
    </Target>
    
Community
  • 1
  • 1
TaW
  • 53,122
  • 8
  • 69
  • 111
  • By "run VS copy", do you mean that you are running two instances of Visual Studio with two different solutions for the "toolbox" and the "tools"? – Sploofy Mar 05 '14 at 07:55
  • Right. I also added a post-build xcopy to copy the dll to the other solution. Works like a charm. – TaW Mar 05 '14 at 08:08

1 Answers1

0

The problem is that the way the MSBuild stuff is setup in the csproj in your solution it will only compile a single .cs file marked with True into one plugin.dll. Thus the compilation fails because your Base class is not compiled, and it's also the reason the partial files won't work.

A simple solution to this is to skip the whole true filtering stuff in the csproj and simply add a CSC line in the BuildPlugins target for each plugin you want to compile like this:

<CSC Sources="Base.cs;Tool1.cs" TargetType="library" OutputAssembly="$(OutputPath)Tool1.dll" EmitDebugInformation="true" />

In the Sources you list the files needed for your plugin and you modify the output path to whatever name of the dll you want.

However, in your case I would probably recommend that you add a project per tool to the solution instead.

Sploofy
  • 493
  • 5
  • 13
  • Cool! That's just the right compromise. As for the project per tool suggestion: I guess I'll do that for tools that are unrelated and don't share a lot. I've run into two new problems, though. One is about the XCOPY copying the old version, the other about upcasting to the base class getting an invalidcast error. see [link](http://stackoverflow.com/questions/22203512/why-does-my-post-build-xcopy-always-copy-the-previous-version-or-hang) and [link](http://stackoverflow.com/questions/22205198/c-sharp-why-cant-i-upcast-to-my-plug-ins-base-class). – TaW Mar 05 '14 at 17:52
  • **OK, Here is the final answer: The above suggestion is close but not quite correct.** If I compile the base class into the DLL directly by adding it to the sources it will not be identical to any other build which tries to reference it. So I can't upcast to the base in the consuming programm. Therefore the reference must be added to the csc line like this: `` – TaW Mar 07 '14 at 09:33
  • **Add and add to the final answer**: For unfathomable reasons, the build file also does not honour the other dependencies, especially the connection of the partial classes of, say usercontrols; so I have to add the 'usercontrol.designer.cs' to the sources. Sigh.. (The above worked because I had butchered the designer.cd and patched into the cs file. (arghh..)) – TaW Mar 13 '14 at 10:39
  • All this trouble is why I recommended that you use separate projects instead. :) – Sploofy Mar 13 '14 at 13:13
  • Yeah. Well. I have already about a dozem small tools ready and the number will grow. It is fine to keep some in common libraries but for the bigger ones I will go with separate libs. The libary manager in the toolbox is in place and works fine. But I really want all options. BTW: I still haven't managed to include the resourcefile to the build. There must be a way.. – TaW Mar 13 '14 at 20:32