Search code examples
visual-studioprojects-and-solutionssolution

is it possible to generate Visual Studio solution files using StylusStudio?


i was wondering if it is possible to generate some kind of template that i give an xml or xsl file in stylus and generate c# code

i made some .cs and works fine, but i couldn't with csproj and sln files,

so, thats why i am asking

i used to program dlls on c# is a n-tier programming


Solution

  • Stylus Studio includes both XSLT and XQuery, and with either you can write text files. So you can manually write a .sln file, if you have the proper source - because .sln files are not XML. Project files, like .vbproj or .csproj, are XML and can easily be created by Stylus Studio.

    Is that what you are asking?

    If you have a XSLT or XQuery program, you can choose to generate code to drive that transform. It will create a Visual Studio project for you. For XQuery, it will use the .Net Saxon XQuery engine. For XSLT, several different XSLT engines for .Net are supported.

    Use the "XQuery > Generate Code > Generate C# Code..." or "XSLT > Generate Code > Generate C# Code..." options to actually create the code and attendant .sln file.

    If however, you do want for some reason to use XSLT inside of Stylus Studio to create a .sln file, here is how you might go about it.

    Sample input file: FAE04EC0-301F-11D3-BF4B-00C04F79EFBC Watchdog DB3FBB37-100C-40DD-B154-153E3F3A68FF

    Sample XSLT file to create .sln from above .xml:

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
        <xsl:output method="text"/>
    
        <xsl:template match="/">
            <xsl:text>&#xD;&#xA;</xsl:text>
            <xsl:text>Microsoft Visual Studio Solution File, Format Version 10.00&#xD;&#xA;</xsl:text>
            <xsl:text># Visual Studio 2008&#xD;&#xA;</xsl:text>
            <xsl:apply-templates select="projects/project" mode="a"/>
            <xsl:text>Global&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;GlobalSection(SolutionConfigurationPlatforms) = preSolution&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;&#9;Debug|Any CPU = Debug|Any CPU&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;&#9;Release|Any CPU = Release|Any CPU&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;EndGlobalSection&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;GlobalSection(ProjectConfigurationPlatforms) = postSolution&#xD;&#xA;</xsl:text>
            <xsl:apply-templates select="projects/project" mode="b"/>
            <xsl:text>&#9;EndGlobalSection&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;GlobalSection(SolutionProperties) = preSolution&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;&#9;HideSolutionNode = FALSE&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;EndGlobalSection&#xD;&#xA;</xsl:text>
            <xsl:text>EndGlobal&#xD;&#xA;</xsl:text>
        </xsl:template>
    
        <xsl:template match="project" mode="a">
            <xsl:text>Project("{"</xsl:text>
            <xsl:value-of select="../guid"/>
            <xsl:text>}") = "</xsl:text>
            <xsl:value-of select="name"/>
            <xsl:text>", "</xsl:text>
            <xsl:value-of select="name"/>
            <xsl:text>\</xsl:text>
            <xsl:value-of select="name"/>
            <xsl:text>.csproj", "{</xsl:text>
            <xsl:value-of select="guid"/>
            <xsl:text>}"&#xD;&#xA;</xsl:text>
            <xsl:text>EndProject&#xD;&#xA;</xsl:text>
        </xsl:template>
    
        <xsl:template match="project" mode="b">
            <xsl:text>&#9;&#9;{</xsl:text>
            <xsl:value-of select="guid"/>
            <xsl:text>}.Debug|Any CPU.ActiveCfg = Debug|Any CPU&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;&#9;{</xsl:text>
            <xsl:value-of select="guid"/>
            <xsl:text>}.Debug|Any CPU.Build.0 = Debug|Any CPU&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;&#9;{</xsl:text>
            <xsl:value-of select="guid"/>
            <xsl:text>}.Release|Any CPU.ActiveCfg = Release|Any CPU&#xD;&#xA;</xsl:text>
            <xsl:text>&#9;&#9;{</xsl:text>
            <xsl:value-of select="guid"/>
            <xsl:text>}.Release|Any CPU.Build.0 = Release|Any CPU&#xD;&#xA;</xsl:text>
        </xsl:template>
    </xsl:stylesheet>