I have a solution contain one class library and one JavaScript file. I want build it into dll file and then call a function in that file.
If this is for a web project (which I'm assuming) why do you want to do it this way? Is this for deployment of your single library to others?
You need to embed this as a resource which wil lthen use ScriptResource.axd.
See:
http://msdn.microsoft.com/en-us/library/system.web.handlers.scriptresourcehandler.aspx
Related
I'm new in .Net and working with two projects in c# a class library project(dll) and a website asp project.
I need to read some properties from a file .resx that is in the App_GlobalResources folder of the website.
Is there a way to read these properties in the .resx website file from a dll assembly more specifically in the method onPreRender??
Thanks for you attention
It sounds to me that you are having some problems with structuring and dependencies in your solution. (Trying to reference the website from a DLL)
Generally speaking, your DLL should not need to access the resources of the website on its own - you should only pass them in through as parameters when calling various methods that are contained in the DLL itself.
Have you thought about migrating the resource file to the DLL?
That would allow both DLL and the website to read from it.
Another option would be to migrate the setting you need to the .config file which you can read by using the ConfigurationManager class ( MSND Link )
You should be able to use it like this, even from your Code repository project:
string settingValue = ConfigurationManager.AppSettings["YouSettingNameHere"].ToString();
However, if you really want to keep your current solution structure you can follow the answer that Pavel Chuchuva gave on a similar question here.
Hi I do not know if this is possible or not but I have a c# Project lets say A and I am trying to access Assembly Info of another project B so that i can get Method Info of project B using Reflection. Problem is that i can not think of a way to integrate those two. Project A provides a openFileDialogue and it selects .csproj file. Reads it and extracts what files are being used in project B.
Can you suggest me a work out?
I don't think you can do that by using reflection. To work with reflection you'll need an assembly, not csproj (or cs files). You should look for a parser, maybe use the Roslyn APIs, that will give you information about the source code in syntax tree format.
http://blogs.msdn.com/b/visualstudio/archive/2011/10/19/introducing-the-microsoft-roslyn-ctp.aspx
Each .csproj file is XML, so you can read that in pretty easily. Listed in that file is every file included in the project, so you can parse the XML .csproj file to find all the .cs files.
From there, if you need to extract MethodInfo, you would have to either parse the .cs files, or use something like Roslyn to parse the code into its syntax tree, and find the methods that way.
Can you just use the built assembly (.exe or .dll) from "Project B" instead of its .csproj file? It would be a lot easier to load the assembly's reflection info, and just loop over every class and evey method...
Use Assembly.LoadFile to load directly the compiled assembly - i.e. the DLL or EXE; this will give you an Assembly object on which you can call GetTypes() etc. to access all the info you want.
Can anybody provide some code block to add an existing C# file to a project.
I have 2 projects in my solution. One project generates C# class files which will be use by second project. I have to incluse these generated files in the second project and build the project. It should be done through programatically. I know that to include these files I have to edit the C#project file (which is an XML) and make an entry that file. But I thought of
using existing code if anybody has it.
Thanks
You can ahve a look at the MsBuild.Engine namespace. It allows you to manipulate a csproj in a consistent way so you can oper the target project and add the reference programmatically.
I want to move the localized resource files, created for my various winforms, to a resource dll. Is there an easy way to do it, that don't include manually reading every single string from the dll for each form, just like the forms usually handles it?
I don't think it'll be that difficult, you just have to create a new project of type class library and move your resource file to that project, when you build that project it'll create the dll and then you just need to refer this dll to your actual project and done.
I'm trying to create a game editor using a C# form, and I've run into a problem when it comes to deserializing; I can't use the content pipeline in a forms application as I don't even have the option to add any content reference to the project. How can I use the content pipeline with my form app? Is there another way to load and deserialize my XML content?
Manually edit the .csproj file and add the following in the first PropertyGroup section which contains the assembly name, project guid etc.
<ProjectTypeGuids>{6D335F3A-9D43-41b4-9D22-F6F17C4BE596};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
You'll probably need to also add
<XnaFrameworkVersion>v4.0</XnaFrameworkVersion>
<XnaPlatform>Windows</XnaPlatform>
Reload the project in VS, and you should be able to add content references to it.
The two GUIDs specified there are for Windows and XNA (Windows). Here is a list of some common project type guids (although slightly dated) if you need to retarget the project at all.
Take a look at the Winforms Series 2: Content Loading AppHub sample.
Basically you load and call appropriate microsoft.xna.framework.content classes to read your compiled xnb files.
You'd use classes in the namespaces within microsoft.xna.framework.content.pipeline to create the xnb files (which is what the content project would do for you).
See here for an overview of the content pipeline: What is the Content Pipeline?
Is there another way to load and deserialize my XML content?
Yes, use any .net method of serialising you want, maybe XDocument.