I have a non-compiled web app which has several pages that all have similar functionality. If I compile the code it's easy to share classes between files, but I'm having trouble achieving the same without compiling. If I have an XmlRequest.cs file, how do I access its class from Compare.aspx.cs?
If you add XmlRequest.cs to a folder named App_Code, it will be available throughout your webapp.
Related
Maybe this is the wrong question. I don't understand the hierarchy/relationship between solutions and projects, so I'll describe my goal first. I have a forms application which works. I want to copy everything in it to another folder on the same PC with a different name which reflects the purpose of a new forms app I want to build. I want to use the old parent which I copied as a skeleton, a starting point. I've tried copying the whole WindowsFormsApplication1 and renaming it, but when it builds, it refers to stuff in the old parent folder. I want each of these to be totally self contained, not reference something above the new folder I just made with the skeleton.
Can someone describe the relationship between projects, solutions, the folder which gets created called WindowsFormsApplicationx and the .sln file? If this is too general, I'd be happy with just some step-by-steps to accomplish my goal.
Thanks for your patience,
Lamar
Thanks onlinecop, this helps but I’m still not all the way there.
When I created the forms application, it made a set of files and directories in the Studio2010/Projects directory:
WindowsFormsApplication2.sln
WindowsFormsApplication2.suo
WindowsFormsApplication2 (folder)
Bin (folder)
Obj (folder)
Properties (folder)
Form1.cs
Form1.Designer.cs
Form1.resx
Program.cs
WindowsFormsApplication2.csproj
WindowsFormsApplication2.csproj.user
I used Forms Designer to make a presentation layer, which although it doesn’t change much, it does change some.
I want to start with all of these and may or may not make changes to them but I will want to change all of their names.
Besides changing the names, most of my changes are in the Form1.cs and wherever Forms Designer keeps its changes. Since it is a graphical input and not text, I don’t know where it stores its stuff.
I’d like to do this without disturbing anything with the originals.
Almost none are unit tests, and most are new, addressing different applications so I don’t want to depend on a version control tool.
I’d like to not use them by reference, but instead by copy because I want the parents sequestered and unchanged.
So it would seem that I would want these to have completely different solutions, not projects inside of a solution….is this right?
Will the “Add Existing” do this for me, and where should I do it
As I’m reading the tutorials, my impression is that basically a solution is associated with an application and projects are sub-entities which might be incremental changes to host unit tests or debugging.
So since I want to make a completely different application, which I do not want to have confused with the parent, I’m thinking I want a new solution. But I want to use most of what I had in the parent so how can I create a new solution and populate it with the contents of the old source files and rename them? I’d like to not have them called Forms1.cs and WindowsFormsApplication2…..more something descriptive of what they are, like NeutronMigrationAnalysis…
If I’m asking the wrong question, it might become clearer if I understood when I should create a new solution instead of a single one with a gazillion projects in it.
Thanks!
Lamar
A solution contains multiple projects.
Let's say that you create a Unit Test. That test will run methods that you've created in a different project, just to ensure that those methods work correctly. So within this solution, you actually have two projects: one which is your normal forms app, and one that is a Unit Test which you, as a developer, can see but that end users won't.
The folders are merely hierarchal in nature: It helps you keep your projects separate, and files in places easy for you to find.
So take your original forms project, within your master solution. Your solution file (usually a .sln file) defines that you have a single project within it, and the directory where it's stored. It usually keeps track of other general or global information as well.
The forms project contains its own project file (usually a .csproj file), and is usually found within whatever subdirectory it was initially started in. That will define all the files that you want included, all of the special build options, the logical layout of your folders, files, and resources, and so on.
When you want to recreate a skeleton project, you will usually create a new, empty project. Then, copy all of the source files into it from your form project and "Add existing..." the files so they are seen by this project. Doing it this way will prevent the .csproj file from being copied from the original project and keeping all those old parent folder files/references.
I need to make a ClassLibrary, to contain different Resource Files (resx). This needs to be done, so I can reuse these resources on multiple projects.
After reading for quite a while on how to achieve this, I'm still nowhere near close to an answer.
Note that i need to achieve this in a way that I don't have to recompile the proyect if I want to change a value
Is there a simple way to achieve this that I'm missing?
Hate to be the bearer of bad news, but I'm afraid you're trying to use RESX files for something other than what they're designed to do. RESX files are compiled into .resources files, which are then embedded into the assembly during the build. In other words, if you don't recompile, you won't see any changes that are made to the resx file reflected in the module.
The benefits of RESX files extends far beyond providing compiled cultural/language text tightly coupled to a deployed solution. They have the potential to provide a simple and flexible set of content managed outside the software development process. Some views here:
What are the benefits of resource(.resx) files?
Yes you can work with your RESX files without having to compile them. See here:
Edit ASP.NET MVC 3 resx files in deployment server without recompiling
Yes you can share RESX files between different projects and even roll your own resource manager. You can maintain alternate sets of resources, serving up alternate content depending on for example the user context. I have been involved in a project where we implemented something along these lines to great affect, in my case the solution was used to provide white labeling. Some detail to get you started here:
http://msdn.microsoft.com/en-us/library/aa905797.aspx
What ways have people found/used to add functionality to a .NET/C# app without recompiling?
The methodology that comes to mind for me is having code that looks for a file to read, parses that file, and then dynamically creates controls and their event handlers, etc., based on what is contained in the file (possibly an xml file).
Or would dynamically loading .DLLs be considered "not recompiling"?
Any ideas/"war stories"?
All you need - MEF - Managed Extensibility Framework
For fairly simple cases with well defined behaviors:
Define an interface for you plugin.
Implement the interface in dlls.
Load dlls with Assembly.LoadFrom.
I'd add a GUID to each dll too so you can tell them apart.
Look at how ASP.Net does it - you can add ASPX/ASPX.cs file while site is running. Short version: ASP.Net listens for file changes and compiles new files into new assemblies, than loads into existing AppDomain to use for rendering new pages.
me and a friend are working on some software in which custom variables need to be inserted into the code for each customer. Whe thought about using a seperate text file but for portability and security we want to include the variables into the .exe.
I have looked at tutorials like this one :
http://www.c-sharpcorner.com/UploadFile/dommym/5598/
or this one :
http://support.microsoft.com/kb/304655
to use asp.net to get the client's data, insert it into the source and then compile it. But these articles only talk about single file sources and our main project has multiple .cs files. So my question was : how would I compile a whole project instead of just one file ?
You can use embedded resource files for this.
You can reference the embedded strings from anywhere in the project.
I'm having a brain fart at the moment. I have a set of files that are read in by a class library in a .NET Web Site. The issue is the files are used in three different sites (all the sites reference the class library), so I don't want to copy the files across all three. What I want to do is have a folder in the class library itself as a shared resource, something like this:
ClassLib
\Templates
-file1.xml
-file2.pdf
-MyClass.cs
and have MyClass read the files from the Templates directory. Easy enough, except that MyClass.cs is called from a page, let's call it Default.aspx. Now MyClass.cs has code like the following:
IList<string> files = GetTemplateFiles(); // returns the path to the template files e.g. Templates/file1.xml
foreach (string file in files) {
if (File.Exists(file)) {
// do things here...
}
}
File.Exists is always false, seemingly because it is looking in the default directory and not the path to ClassLib (which is something like C:\Projects\Shared\MyLib\). Now, I cannot use AppDomain.CurrentDomain.BaseDirectory because this varies based on the web site which is calling it; the templates should always be available from the Templates directory in the class library, not the calling application. The properties in Assembly.GetExecutingAssembly() don't seem to be of much help either, pointing to ASP.NET Temporary Files.
Basically my question is what the best way to handle this would be. The template files should be a shared resource available to every application (and not copy/pasted into three Templates/ directories in each application), but I don't know which application will call it at a given time so I need to avoid hard-coding the file path to the templates folder. I'm missing something small but critical in how I'm trying to retrieve the template file, but I can't figure out exactly what.
Decide on a common, shared path available to all three sites and define that path in your web.config files, making sure that IIS is able to access that shared folder.