Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
56 views
in Technique[技术] by (71.8m points)

c# - Visual studio one project with several dlls as output?

I'm programming a project with plugin support. Since many of the plugins are relatively small (only one source-file/class) I would like to have them all in one project in visual studio, but to successfully do this I would need each source-file/class to be compiled into its own dll file, is this possible using visual studio?

If this is not possible with visual studio, would it be possible using another build system, while still coding and debugging with visual studio?

Currently I've set the plugins project output type to console, and programmed a main() method that will compile all .cs files in the source directory to dlls and copy those to the proper directory. Then I set that console app to be the post-build event of the plugins project. It works, but it seems like a very ugly hack.

Using visual studio 2010.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could create one project for each plugin and group all projects in a solution.

If you don't want to have one project per plugin, you could create a custom build with MSBuild using CSC task

How to generate a dll for each plugin file

  1. In a project you add all plugins files

  2. Edit the project file to specify which class will generate a plugin library :

    <ItemGroup>
      <Compile Include="Class1.cs">
        <Plugin>true</Plugin>
      </Compile>
      <Compile Include="Class2.cs" />
      <Compile Include="Class3.cs">
        <Plugin>true</Plugin>
      </Compile>
      <Compile Include="Program.cs" />
      <Compile Include="PropertiesAssemblyInfo.cs" />
    </ItemGroup>
    
  3. Add a new target in your project file to generate the plugins library

    <Target Name="BuildPlugins">
      <CSC Condition="%(Compile.Plugin) == 'true'"
           Sources="%(Compile.FullPath)"
           TargetType="library"
           OutputAssembly="$(OutputPath)%(Compile.FileName).dll"
           EmitDebugInformation="true" />
    </Target>
    
  4. If you want to create the plugins library after each build, add an after build target :

    <Target Name="AfterBuild" DependsOnTargets="BuildPlugins">
    </Target>
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...