aewarnick Posted April 29, 2003 Posted April 29, 2003 (edited) I know how to use the csc program for VS to create a dll file of a class that has no user interface: csc /target:library /out:"D:\My Documents\C Sharp projects\ProgramAW.dll" "D:\My Documents\C Sharp projects\Andrew.cs" But how would I create a dll if it needs to hold all the information about the Form so I can just put using MyDll at the top and call a method in the dll to show and run the form? Edited April 29, 2003 by aewarnick Quote C#
*Gurus* divil Posted April 29, 2003 *Gurus* Posted April 29, 2003 It works the same. Forms are just classes, after all. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted April 29, 2003 Author Posted April 29, 2003 (edited) Here is the error I get: An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll Additional information: Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "xForm.resources" was correctly embedded or linked into assembly "x". baseName: xForm locationInfo: x.xForm resource file name: xForm.resources assembly: x, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null Here is what I did: csc /target:library /out:"D:\My Documents\C Sharp projects\x.dll" "D:\My Documents\C Sharp projects\xForm.cs" I put using x at top The call: xForm p=new xForm(); p.Show(); Edited April 29, 2003 by aewarnick Quote C#
*Gurus* divil Posted April 29, 2003 *Gurus* Posted April 29, 2003 When you have binary resources in your form (pictures, icons etc) the command line gets more difficult. You will need to manually convert the form's .resx file in to a .resources file using the .net framework classes ResXResourceReader and ResourceWriter. Then you can use the /resource command line parameter to specify each resource file to embed in the file. The filename IS important - I think it should be the root (or default) namespace of your assembly plus the form name, separated by a period. Or you could purchase a non-crippled version of VS.NET which does it all for you :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted April 29, 2003 Author Posted April 29, 2003 Is there a web page that you know of that has an example of how to do this? I have never used those classes. Quote C#
*Gurus* divil Posted April 29, 2003 *Gurus* Posted April 29, 2003 I don't know of one. Use the help to examine the methods of those two classes, use one to read and one to write each resource in the files. It's not trivial. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted April 29, 2003 Author Posted April 29, 2003 (edited) When I use ResourceWriter to write the .resx file to the program from the contructor before initializeComponent (I guess that would be the best place), the resx file will not be on somone elses computer and it will be looking for it, right? Maybe I don't understand how this works, but there was no good documentation in help. Nothing even remotely close to what I am doing. I tried adding an existing item (the resx file) from the Solution Explorer but when I try to add it, nothing happens. I thought I could just make it an embedded recource but I could not. Maybe I am trying to embed it in the wrong solution. Do I embed the resx file in the same solution it comes from (which is also the files I will create the dll from), or the solution that is going to show the form? Edited April 30, 2003 by aewarnick Quote C#
*Gurus* divil Posted April 30, 2003 *Gurus* Posted April 30, 2003 The resx file is *already* embedded in your solution. VS.NET converts it to a .resources file whenever it builds the project. This conversion isn't something you do in your program, it's something you'll want to make another program to do if you're trying to build the solution from the command line. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted May 1, 2003 Author Posted May 1, 2003 I hate to ask this Would you mind giving me an example of how to do this. . .All I could find on the internet was how to do it with the non-crippled version of VS. And I don't have the money right now to go out and but it. Quote C#
*Gurus* divil Posted May 1, 2003 *Gurus* Posted May 1, 2003 If you remind me at the weekend I might just have a little more time then. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted May 2, 2003 Author Posted May 2, 2003 Good news! I may not even have to use the methods you suggested after all. MS made a program that uses them called Resgen. I used it to convert the resx file to a resources file and it worked great! The problem I am having is embedding the resource in the dll. Here are some of the params I wrote in csc: Note: The namespace of this dll is Preach, and the cs file is PreachForm.cs csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs" csc /resource:"D:\My Documents\C Sharp projects\PreachForm.resources" "D:\My Documents\C Sharp projects\Preach.dll" csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs" csc /resource:"D:\My Documents\C Sharp projects\Preach.PreachForm.resources" "D:\My Documents\C Sharp projects\Preach.dll" csc /resource:"D:\My Documents\C Sharp projects\Preach.PreachForm.resources" "D:\My Documents\C Sharp projects\PreachForm.cs" csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs" The dll compiles fine with all of them but when I copy the dll and paste it in the program solution that it is used in (could be any) I get the same error message I got before. Quote C#
*Gurus* divil Posted May 2, 2003 *Gurus* Posted May 2, 2003 It looks like you are trying to call csc twice? There should only be one call when you compile it, with the /resources parameter on the end. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted May 2, 2003 Author Posted May 2, 2003 It never makes the dll this way: csc /target:library /out:"D:\My Documents\C Sharp projects\Preach.dll" "D:\My Documents\C Sharp projects\PreachForm.cs" /resource:"D:\My Documents\C Sharp projects\Preach.PreachForm.resources" "D:\My Documents\C Sharp projects\Preach.dll" I cannot see the error because it closes immediately. I used a batch file to run it. How do I pause the console window so I can see the errors. Quote C#
aewarnick Posted May 2, 2003 Author Posted May 2, 2003 Nevermind, all I had to do is take the last line out and it works perfectly in my program. Thank you for all your help divil!! Quote C#
aewarnick Posted May 3, 2003 Author Posted May 3, 2003 Divil, I think I will take you up on that offer. . . I do not like using the command line for anything! I would like to make my own program to convert resx files to .resources files. I am having trouble figuring out how to first of all, bring a resx file into my program at runtime. The other problem I am having is how to save it as a .resources file to disk from the program correctly. I can do it, but it does not create if the way that resgen does and consequently, does not work. This will get the .resources file to save to disk but, like I said, it does not save right: System.Resources.ResourceManager r = new System.Resources.ResourceManager(typeof(PreachForm)); object o= r.GetObject("Preach.PreachForm.resources"); ResourceWriter R=new ResourceWriter("Preach.PreachForm.resources"); R.Generate(); I have tried many other things including the ResXResourceReader. I don't see logically how using that class could solve my problem but I tried anyway. Remember, I cannot figure out how to bring a .resx file into my program at runtime to convert it to a .resources file when saving to disk. If you would, please help. Quote C#
*Gurus* divil Posted May 3, 2003 *Gurus* Posted May 3, 2003 Here's some old vb.net code I have to do that, I'm sure you can convert it. Dim myResEnum As IDictionaryEnumerator Dim objResourceWriter As ResourceWriter, objResXResourceReader As ResXResourceReader 'Open read and write resources objResXResourceReader = New ResXResourceReader("myfile.resx") objResourceWriter = New ResourceWriter("myfile.resources") 'Loop through myResEnum = objResXResourceReader.GetEnumerator() Do While myResEnum.MoveNext objResourceWriter.AddResource(myResEnum.Key.ToString(), myResEnum.Value) Loop 'Close up objResourceWriter.Generate() objResourceWriter.Close() objResXResourceReader.Close() Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
aewarnick Posted May 3, 2003 Author Posted May 3, 2003 It works perfectly, divil. Thanks alot!!!! Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.