Link to home
Start Free TrialLog in
Avatar of paromitabanerjee
paromitabanerjee

asked on

How to I make a DLL in C# containing xsl file ?

I have a set of xsl file which I have to convert into a DLL and use it in another project. this is urgent.

thanks in advance
SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of paromitabanerjee
paromitabanerjee

ASKER

Hi,

thanks for the prompt reply. I am a fresher in C3. So bear with me.

I have made a project, in which I have embedded all the xsl files I have to use. (this project has a main method which does nothing) Then I compile this project. But I dont find any DLL being created ??

Could you tell me the step by step process for this.

let me explain what is required in the project. ----
This is a Desktop build. XSL files are used while generating PDFs. Uptill now the xsl files were a part of the Database. But now, they have to be made into a DLL, so that they go with the build. and then called from the main project.

Thanks in advance
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi. You need to add the xslt to your project (it will then be compiled into your DLL). In your code You can get access to the XSLT using code like (in my case the filename is BygteqStyleDefXsl.xsl):


namespace ArtesaIP
{

    ///<summary>ItemPriceXSLT er implementeringen af ArtesaIP, der foretager tansformation af leverandør XML til Aretesa XML</summary>
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces(typeof(IArtesaItemPrice))]
    [ComVisible(true)]
    public class ItemPriceXSLT : IArtesaItemPrice
    {
        private int debugLevel;
        private XsltArgumentList XsltArg;
        private BygteqXslFunctions bygteqXslFunctions;
        private XmlDocument bygteqXsl;

 In a methoed:

                //Load BygteqStyleDefXsl.xsl
                Stream s = System.Reflection.Assembly.GetAssembly(System.Type.GetType("ArtesaIP.IArtesaItemPrice")).GetManifestResourceStream("ArtesaIP.BygteqStyleDefXsl.xsl");
                bygteqXsl.Load(new XmlTextReader(s));
                s.Close();

Hope this helps.
Best regards,
Kaj Bromose
Hi All,

thanks for your prompt replies.

Here is what I have done so far,

1) Created a class Library project (Stylesheet50) and embedded all the xslt files in it (about 12 of them) using Build Action == embedded resource property. On compilation, it made a stylesheet50.dll file.
2) I my WinApp project (which has the main method) -- I have included the stylesheet50.dll as a reference.

Now I want to start accessing my xsl file. will using the Assembly methods given above allow me to access the xsl files in the dll ??

thanks in advance

I am not quite sure. In my case the DLL is exposed as an COM DLL wich is called from a Microsoft Dýnamics (Navision) application.

That is why the
    [ClassInterface(ClassInterfaceType.None)]
    [ComSourceInterfaces(typeof(IArtesaItemPrice))]
    [ComVisible(true)]
part of the code.

However I think it will work, since the Navision application in my case act as the exe app. in Your case, but it needs to ve tryed out.

Hope You will succed with the testing.

Sorry - I forgot to give you a hint - you can link from the XSL style sheet to your own C# code by using the XsltArgumentList. I that way you may call your own C# methoeds as XSL functions from your XSL stylesheet - and you may even have a object holding data between multible stylings (fs. bulding an array in one styling to be used in an later styling).

When I just try to get the resource file names from the assemblies, it is not giving the proper file names. My code :

Assembly a = Assembly.GetExecutingAssembly();

 string[] resNames = a.GetManifestResourceNames();

int len = resNames.Length;

                for (int i = 0; i < len;i++ )
                {
                    MessageBox.Show("filenames == "+resNames[i]);
                }


It is giving the following output :--

WindowsApplication3.Form1.resources
WindowsApplication3.Properties.Resources.resources

It is not reading the resource names inside the dll file . Why ??

Is something worng with my code ?

thanks

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mind the language while writing ur code !!!!
Sorry - English is not my native language. I now se that my choise of variable name is unapropiet. I'm sorry if my language has offended anybody - it was clearly not the intention !!!
Thats okie... :) I realized that later.

hey,

I tried the above code. Its reading all the System generated assemblies correctly but not the one that I created. :(  -- heres the code

System.Reflection.Assembly assm = System.Reflection.Assembly.GetAssembly(Type.GetType("WindowsApplication3.ProgramCheck"));
//Your EXE prog namespace and class
                System.Reflection.AssemblyName[] an = assm.GetReferencedAssemblies(); //Gives you the list of ref. DLL assemblies
                int len = an.Length;

                for (int i = 0; i < len; i++)
                {
                    MessageBox.Show("filenames == " + an[i]);
                }

any help ??

Do I have to change or add anything im my assemblyInfo.cs file?

Following is the code in the assemblyInfo.cs  which is under the Properties folder :-

sing System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("StylesheetLTC50")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Company")]
[assembly: AssemblyProduct("StylesheetLTC50")]
[assembly: AssemblyCopyright("Copyright © Company 2006")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.  If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(true)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("27dd18ef-534c-459f-bc54-60353a19222d")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

thanks.
You need to make sure that Your DLL's are in the project. In VS 2005 Open the Solution Explorer vindow and click the "References". If your DLL name is not listed here, you need to right click references and choose add reference. Then select the "browse", and set focus on your DLL.

Once the DLL is in the References list it should work.

yup it is a part of the reference.

Hey, if I use this it is giving me the embedded files :-

                Assembly a = Assembly.LoadFile("C:\\Visual Studio 2005\\Projects\\WindowsApplication3\\WindowsApplication3\\bin\\Debug\\StylesheetLTC50.dll");
                string[] resNames = a.GetManifestResourceNames();
                int len = resNames.Length;
                for (int i = 0; i < len; i++)
                {

                    Console.WriteLine(resNames[i]);
                    MessageBox.Show("filenames == " + resNames[i]);
                }

I will try to put a relative path now and see .

a BIG thanks for the prompt help provided by everyone.... :)