views:

756

answers:

5

Hello, 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

A: 

Visual Studio solution files are not XML, so I wouldn't expect Stylus Studio to do much with them.

Snippet of a solution file:


Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpsUrlWithPort", "HttpsUrlWithPort\HttpsUrlWithPort.csproj", "{9FD67B56-9D49-4989-89D0-06A29ACAA5A3}"
EndProject
John Saunders
I'm not sure what StylusStudio is but I do believe that Visual Studio Solution files are in an XML format.
NotDan
@NotDan: You are thinking about project files.
JP Alioto
+1  A: 

John is correct, you'd be better off using notepad, but there is a free version of Visual Studio 2008 that you can use to create many types of solution if you don't want to invest in a license. If you're trying to do template driven code generation, have a look at CodeSmith.

JP Alioto
A: 

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"&gt;
    <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>
lavinio
A: 

ok, i'm sorry, let me explain again i used to program dlls on c# is a n-tier programing

what i'm trying to do is a some kind of template that i give an xml file in stylus and generate code

i made some .cs and works fine, but i couldn't with csproj and sln files well the true is that i dont know how to do it

so, thats why i am asking

A: 

A: Use t4!

Visual Studio's T4 Code Generation create templates using Microsoft's T4 templating language.

Q: I want to generate some of the code for my application and Microsoft has a code generator, t4.

A: Microsoft has a code-generation tool T4 which stands for Text Transformation Templating Toolkit.

T4 comes with Visual Studio 2008, or you can download it if you're using VS 2005.

Taylor Boswell