Edit: { I think I've added a lot (too much) of information (reading) here. The important bits of what I want is:
- I'm using a Web Site (no .csproj file)
- I need multiple source files of code for my ASPX to run
- From what I understand I either need to use a pre-compiled DLL or tell .NET to compile the additional files on-the-fly when an ASPX file is requested
- I'm not sure how to get either situation to work
- If providing help on a DLL, please tell me what statement to use and put in what file (ASPX directive, web.config, etc -- can't use .csproj)
- If providing help on the other option, please provide the statement to use to include MULTIPLE source files, and where to put the statement (ASPX directive, web.config, etc, -- can't use .csproj) -- I'm already using @Page CodeBehind/CodeFile, I need more than one source file
}
I'm trying to include additional C# source files to my ASPX file, it is not working.
I have Default.aspx (with @ Page CodeFile="Default.aspx.cs") and would like to reference other files (e.g. LinkList.cs, SQLiteDB.cs, SQLServerDB.cs, JSON.cs).
I'm thinking it should be something like this (in the Default.aspx file):
// <%@ Reference Page="secondfile.cs" %>
I am new to ASP/.NET but have some experience with C# and am very experienced with PHP, JS, client-server model, etc. I have tried various ways to include them but to no avail; attempts listed below.
My setup uses a Web Site (compiled on demand; App vs. Site), using a text editor (NOT VS!) to edit the remote files. I started with VS but determined after hours of debugging that my server requires various different settings than my VS project and I do not want to maintain multiple versions of the same code... As such, and as I am on a deadline, even if I could get VS to work with my setup (comments welcome), my primary concern is to just get the code working with the server.
Things that do work:
- all the code from all the C# files merged into one, my CodeFile, does compile; the issue is being able to have each class in a separate file for maintainability.
- as determined from the above link, I need to use @Page CodeFile (NOT CodeBehind); I have determined that this does cause the primary C# file to load
Things that don't work:
- HTML script tag (link); this method does cause the other files to attempt compilation, but get an error on the 'using's in the files, but even when I move the 'using's to the primary source file, the classes in the other files are not recognized as data types in the primary C# file.
- <%@ Reference Page="secondfile.cs" %> (error: "The file 'src' is not a valid here because it doesn't expose a type."; not sure where it's getting 'src' from, I'm not using it and 'src' isn't a valid attribute to Reference...)
- the 'App vs. Site' link specifies that all the files in the directory are included in the compilation, but the other files are not being compiled... all my files are in /www/dev/*, and all my C# files use the same namespace
- <%@ Assembly Name="assemblyname" %> or <%@ Assembly Src="pathname" %>
actually using the following does seem to cause the files to load, but I still get an error: "CS0246: The type or namespace name 'SQLServerDB' could not be found (are you missing a using directive or an assembly reference?)"
<%@ Assembly Src="SQLServerDB.cs" %>
<%@ Assembly Src="DataSource.cs" %>
- including "using myNS.SQLServerDB" produces the same error
I'm not sure what else to try... please help. I've tried various combinations with other asp directives too.
Update/Clarification: What I'm asking is since I'm using a Web Site setup (NOT Web Application), how can I tell the ASP Server to compile other source code with the CodeFile? Answers so far do not address both aspects of this situation. The 'using' command doesn't tell the compiler where the code files are, just desired classes.