Class .cs file outside App_Code folder (VS2008 Website)


L

LenaMsdn08

Good morning! My apologies if this is a dumb question - but I've had no luck
searching for an answer and am on a tight deadline, so ...

I'm working on a tiny part of a huge project that uses the Website model.
I'd like to place some code in a separate class that I can reference from
several pages, but the .cs file for the class needs to be stored outsite the
App_Code folder. (Making *any* changes under App_Code causes the entire site
to recompile, which takes about 4 minutes. Converting to a Web Application is
not an option, for the same reason.)

I'd like to place my pages in a separate folder and place the .cs file for
the class in the same folder, but I keep getting compile error "CS0246: The
type or namespace name 'MyClass' could not be found (are you missing a using
directive or an assembly reference?)". If I place the code for the class
inside the .aspx.cs file it finds it, but I haven't found any way to make it
work with the class in a separate file.

What do I need to make my pages recognize the class? (Please spell out the
details, I'm on a very tight deadline and need to save time everywhere I can.)

Thank you!
Lena
 
Ad

Advertisements

C

Cowboy \(Gregory A. Beamer\)

the problem with putting it anywhere other than App_code is namespaces. I am
not sure what namespace to use to use it elsewhere, but you will have to
accomplish that to get it recognized. I am not sure this will not stop
recompiling, however, as the pages have to recompile to use the new class.

Can you not set up the code in a separate library and reference the library?
It is a much better way to accomplish this.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box! |
*************************************************
 
C

Cowboy \(Gregory A. Beamer\)

the problem with putting it anywhere other than App_code is namespaces. I am
not sure what namespace to use to use it elsewhere, but you will have to
accomplish that to get it recognized. I am not sure this will not stop
recompiling, however, as the pages have to recompile to use the new class.

Can you not set up the code in a separate library and reference the library?
It is a much better way to accomplish this.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box! |
*************************************************
 
C

Colbert Zhou [MSFT]

Hello Lena,

There are only two special Shared Code Folders in ASP.NET Websites project.

1. The App_Code which you do not want to choose
2. The Bin folder

If we go through the second way, we need to use the following command to
compile the shared class file

Csc.exe /target:library /out:MyClass.dll MyClass.cs

Then we create a folder named Bin under the website project folder and put
the MyClass.dll into the Bin folder. After that, the Visual Studio will
recognize all assemblies in the Bin Folder and you can use it in any
aspx.cs files.

More detailed information, please refer the following document,
http://msdn.microsoft.com/en-us/library/t990ks23(VS.80).aspx


Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
C

Colbert Zhou [MSFT]

Hello Lena,

There are only two special Shared Code Folders in ASP.NET Websites project.

1. The App_Code which you do not want to choose
2. The Bin folder

If we go through the second way, we need to use the following command to
compile the shared class file

Csc.exe /target:library /out:MyClass.dll MyClass.cs

Then we create a folder named Bin under the website project folder and put
the MyClass.dll into the Bin folder. After that, the Visual Studio will
recognize all assemblies in the Bin Folder and you can use it in any
aspx.cs files.

More detailed information, please refer the following document,
http://msdn.microsoft.com/en-us/library/t990ks23(VS.80).aspx


Best regards,
Colbert Zhou (colbertz @online.microsoft.com, remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
 
C

Colbert Zhou [MSFT]

Hello Lena,

Any future help needed on this thread?


Regards,
Colbert
Microsoft Newsgroup Online Support Team
 
Ad

Advertisements

C

Colbert Zhou [MSFT]

Hello Lena,

Any future help needed on this thread?


Regards,
Colbert
Microsoft Newsgroup Online Support Team
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top