Gauging interest: Visual Studio custom tool for Slice files

csammiscsammis chris sammisOrganization: blankProject: blankMember
Hello all -

I've been working with Ice for several months now, we use it to communicate between C++ data servers and C# client apps. On the C# side, most of us use Visual Studio 2003 to do our development. We have a project, call it IceClient, that encapsulates the classes generated by slice2cs, and the rest of our projects contain a reference to the IceClient project.

The problem (as I see it) with this setup is the way that we use slice2cs in the IceClient project: a pre-build step is used to call slice2cs on our Slice files. This has the unfortunate side-effect of rebuilding the C# files each time, which causes the IceClient project to have to rebuild itself each time, which causes all projects that are dependent on IceClient to rebuild...it's a time-consumer.

To fix that, I've written a custom tool for VS 2003 that understands how to handle Slice files. The Slice file is included in the project, its "Custom Tool" property is set to "vsSlice" (the name of the tool), and the problem is solved: VS now knows enough to only regenerate the C# when the interface file has changed, which means that the cascading rebuilds don't happen and overall compile time is usually sped up.

What I'm wondering now: Would anyone else be interested in this tool for their own use? I've found it pretty handy, and I'd like to share it if there's interest -- plus, other people using it will allow me to test it outside of our own build environment, always a good thing ;)


(mods, if this thread would be better served in another forum, please move)

Comments

  • michimichi Michi HenningOrganization: Triodia TechnologiesProject: I have a passing interest in Ice :-)Member ✭✭✭
    Feel free to post any tools you want to share here.

    BTW, the icecs source tree includes a tool that does just that: finds all the Slice files and compiles them only if they are newer than the corresponding generated .cs files. You can find the code for this in the generate subdirectory of the icecs tree.

    The tool isn't terribly sophisticated, but good enough to support the build for icecs. (Unfortunately, support for custom build steps is rather rudimentary with VS for C#, and even more rudimentary with VS for VB, so you end up having to write tools such as this...)

    Cheers,

    Michi.
  • sylvainsylvain Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systemsMember ✭✭
    ... still available?

    Hi Csammis,

    I was just about to start building from scratch the "Custom Tool" you describe in you post (with no idea on how to do it), for exactly the same reason you first made it.

    Your post is about 2 years old, but are you still using your tool, and are you still ok to share it?

    I have to say we use VisualStudio 2005, but it is probably the case for you too, and your tool might work as is in VS2005.

    Anyway, I would be quite happy to get it if you don't mind, for sure it will be quite useful for me.

    Thanks in advance.
  • csammiscsammis chris sammisOrganization: blankProject: blankMember
    Sorry sylvain, I no longer work at the company where I used Ice.
  • sylvainsylvain Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systemsMember ✭✭
    Hi Csammis,

    Ok, thanks for your reply anyway.

    I will thus develop the Custom Tool myself, and post it here if it seems to work.

    Regards.
  • dwaynedwayne St. John's, NewfoundlandDwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications EngineMember
    Have you looked at what we do in the demo project files? Since we no longer support VS 2003, the slice compilation is now part of the project rather than an external tool.
  • sylvainsylvain Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systemsMember ✭✭
    Hi Dwayne,

    thanks for your reply!

    Well, I did look at your demo-projects, and indeed .ice files are slice2cs'ed before the build start.

    I managed to find the lines
    <Target Name="CompileSlice" Inputs="Hello.ice" Outputs="generated\Hello.cs">
    <Exec Condition="Exists('..\..\..\slice')" Command="..\..\..\bin\slice2cs.exe --output-dir generated Hello.ice" />
    <Exec Condition="Exists('..\..\..\..\slice')" Command="..\..\..\..\cpp\bin\slice2cs.exe --output-dir generated Hello.ice" />
    </Target>

    in the .csproj fille, but I have not been able to find a way to edit or add this using project properties from VisualStudio. How did you do that??

    I have to say that your solution might be nice to start with, but will not replace the Custom Tool stuff. Indeed, using a Custom Tool will make .ice files to be sliced anytime you save them.
    This is nice if you use tools like Resharper that parse code and find errors without the need to compile.

    Thanks again.
    Regards.
  • dwaynedwayne St. John's, NewfoundlandDwayne BooneOrganization: ZeroC, Inc.Project: Internet Communications EngineMember
    sylvain wrote: »
    Well, I did look at your demo-projects, and indeed .ice files are slice2cs'ed before the build start.

    I managed to find the lines
    <Target Name="CompileSlice" Inputs="Hello.ice" Outputs="generated\Hello.cs">
    <Exec Condition="Exists('..\..\..\slice')" Command="..\..\..\bin\slice2cs.exe --output-dir generated Hello.ice" />
    <Exec Condition="Exists('..\..\..\..\slice')" Command="..\..\..\..\cpp\bin\slice2cs.exe --output-dir generated Hello.ice" />
    </Target>

    in the .csproj fille, but I have not been able to find a way to edit or add this using project properties from VisualStudio. How did you do that??

    I manually edited the *.csproj files and added it. Not ideal, but it met our needs.
  • sylvainsylvain Sylvain FaselOrganization: university of GenevaProject: quantum cryptographic systemsMember ✭✭
    I see, nice hack!

    I now understand why I had these warnings while opening the solution.

    You could basically run whatever you want using this tweak, frightening! ;)

    Regards.
  • kwaclawkwaclaw Oshawa, CanadaKarl WaclawekOrganization: PersonalMember
    dwayne wrote: »
    I manually edited the *.csproj files and added it. Not ideal, but it met our needs.

    I played around with this approach and it seems the following recipe works also:
    1. Add your Slice files to a Visual Studio project and on their properties page assign them a custom Build Action name, e.g. "Slice".

    2. Add the files to be generated (as empty code files, for instance) and on their properties page assign them a custom Build Action name, e.g. "SliceGenerated".

    3. Add this <Compile> item in the project file:
      <ItemGroup>
          . . .
          <Compile Include="@(SliceGenerated)">
            <Visible>False</Visible>
          </Compile>
          . . .
        </ItemGroup>
      
      The <Visible>False</Visible> tag prevents double display in the Visual Studio IDE.

    4. Paste this to the end of the project file (part of it copied from ZeroC demo projects):
      <Target Name="CompileSlice" Inputs="@(Slice)" Outputs="@(SliceGenerated)">
          <Exec Command="%25ICE_HOME%25\bin\slice2cs.exe -I&quot;..\slice&quot; --output-dir generated @(Slice->'&quot;%(Identity)&quot;', ' ')" />
        </Target>
        <Target Name="AfterClean">
          <Delete Files="@(SliceGenerated)" />
        </Target>
        <PropertyGroup>
          <CompileDependsOn>
            CompileSlice;$(CompileDependsOn)
          </CompileDependsOn>
        </PropertyGroup>
      
      This last step requires that ICE_HOME is a defined environment variable, and that the parameters for slice2cs are properly set, like include directories (-I) and output directories ( --output-dir).

    Karl
Sign In or Register to comment.