Not so much a direct programming query - more just for info/knowledge...
When I click on Publish (VS2012 RC), and I look in the release folder, I can only see folders for bin, content, images, scripts and views.
There is no controllers folder.
Is this because VS packages up everything into the DLLs within the BIN folder?
Thanks, Mark
The DLLs inside your bin folder has the code for the controllers and other class files(Ex : Your Model classes). If you use any decompiling tool, you can see that.
DLL (dynamic-link library) files contain the executable code for the Web site, such as the class file that you created. Your application will works fine with those DLLs because all your code(your methods/ properties etc..) is available in that.
Your controllers (and any other .cs files) are compiled into a dll in the bin folder.
Related
When I use Vs 2012 Express edition to create a website , I remember I should place the class file *.cs in the system folder \App_Code, and Vs 2012 can compile these files automatically. It's OK.
When I use Vs 2019 (Microsoft Visual Studio Community 2019), I find the the class file *.cs in the system folder \App_Code can't be compiled automatically, I have to set it by myself, you can see Image A.
But if I place the class file *.cs in in root folder of a project , they can be compiled automatically, it seems that Vs 2019 set Compile option as default, you can see Image B.
Is is a bad way to place the class file *.cs in the system folder \App_Code when I use Vs 2019 ?
Image A
Image B
It is not good or bad to place a class file *.cs in the system folder App_Code when you use VS2019 or some other VS, it depends on your goal for those files.
TLDR: put non user control sources in App_Code if you need server-side behavior (on the fly updates), but don't mark its build action as compile but rather content, and therefore forget about benefiting from IntelliSense.
For a website project, you have the special folders Bin and App_Code, for code shared between pages. Files inside App_Code do not have to be source code, it can be a content file. Files inside are handled by asp.net in special ways (1).
Source code inside App_code and subfolders are automatically compiled at runtime. When the website is running, you can update those source code, and they will be recompiled on the fly, just like Live unit testing in VS (1). This will happen when the website is running on the server too (2).
The App_Code folder and its special status in an ASP.NET Web
application makes it possible to create custom classes and other
source-code-only files and use them in your Web application without
having to compile them independently. (1)
But
User controls are not allowed in the App_Code folder. This includes
both single-file user controls and user controls that use the
code-behind model. Putting a user control .in the App_Code directory
causes the user control's code to be compiled out of its required
sequence and therefore is not allowed. Note that user controls do not
need to be in the App_Code folder; they are already available to pages
anywhere in the application. (1)
I add that you should not add source code in App_Code and leave it marked compile as build action, because then it will be both compiled by VS and asp.net, leading to duplicate references. Instead, leave it as content, but then IntelliSense won't see them as source code. (2)
Vishal R Joshi (2) gives the piece of advice:
You can add code files under any folder call it “CodeFolder”,
“Controllers” or anything that makes sense in your project… Just avoid
putting them under “App_Code” unless you specifically want the server
side compilation behavior… (2)
References:
Shared Code Folders in ASP.NET Web Sites
App_Code folder doesn’t work with Web Application Projects (WAPs)
I get some troubles with a DLL reference.
I have MySql.Data.dll in my bin folder. And I added the reference of this dll to my project.
I can well use classes from this dll (like MySqlConnection, MySqlClient, etc) in aspx.cs but i cannot use it in classes from files from App_Code folder !
For all files situated in App_Code folder (my model classes) , the using MySql.Data; doesn't work. While it works in aspx.cs files.
As you know, there are two types of projects that you can use to create a website in Visual Studio. The App_Code folder works for Web Site projects, but since you stated that you're using a Web Application project, this is causing you problems.
Here's some additional reading on this topic.
In short, I recommend just creating a different (non-built-in) folder to put your random code files in. Name it something like "code", "classes", etc.
at vs2008 i could set App_Code folder, but at vs2010 i can not do it, that's why i put my dataset's and class' to App_Data folder. Either I do not know even App_Data folder is secure? Any suggestions?
Thanks
Remember, that Web Site Project can contain App_Code folder and Web Application Project can't! Because all project is for code.
If you want to add the App_Code folder, you have to manually add the folder.
Add->Add New folder--> you have to give it the folder name "App_Code"
when you do it, and vs2010 automatically will change its folder type.
good luck
If you want to use standalone class files (in "App_Code" dir) in VS 2010 project, be sure set the File Properties > Build Action for each *.cs or *.vb file to "Compile" in the Properties > Advanced dialog.
Also, use the same namespace as your project and these standalone classes will be readily available to the rest of your project.
Took me a bit to realize the default setting in my VS was "Content" instead of "Compile."
Have you tried right-clicking on the project in the Solution Explorer, selected 'Add...' and looked under ASP.NET folders?
From memory, even previous versions of VS don't automatically put the App_Code folder in your project by default.
If you just create a folder called App_Code it will recognise it as the App_Code you want, it is strange that in the add .net folder it doesnt appear.
This the route I took for it, and it all works fine.
Workaround:
If we are using App_Code in a web application project, we need to
rename into any other folder name.
http://blogs.msdn.com/b/chiranth/archive/2014/02/19/visual-studio-2012-unexpected-behavior-crash-and-irrelevant-errors.aspx
I hope this will help you - the .cs files should not be placed in a folder. Just put them in the project, alone, and not in a folder. Then your classes will be visible. This is a difference in VS 2010.
I am looking for some advice on how what is the best approach to subweb folders and having mutliple bin folders in the WebSite Project model. For adding new pages at a later stage without recompiling the core files of a website and without building a full fledged Plug-in framework api. I am aware of being able to drop in the compiled dlls into the main bin folder and to just copy over the new page files to a sub folder but I am looking for a more organized file/folder approach.
Here is the how it was done with WAP:
Moving the Code-Behind Assemblies/DLLs to a different folder than /BIN with ASP.NET 1.1
Multiple /bin folders in ASP.NET
I should also mention that I see that I can still do it the old way with the website project model by making the adjustment to the config section mentioned here but I was wondering if that has any side affects.
AssemblyBinding in Web Config and XMLNS
Are you trying to copy new DLL's or new sources to your site? Note that for sources, the best place in web sites is the App_Code folder. In there, you can create any arbitrary folder structure that you like, and it will all be built at runtime into an assembly. Then, every page gets a reference to that assembly and is able to use types from there.
I need to use a dll in my asp.net application. How do I load a dll not from a bin directory?
Perhaps I should mention that the application is a mixture of asp code and asp.net code.
so, when I develop it on my machine, I place a dll in the bin directory, but after I move the code to the live environment, I don't want to have a separate bin directory for every piece that's using asp.net.
All I am moving is .aspx and .aspx.cs files. Is there a way to load a dll NOT FROM /bin (specify it with "using" statement)? Looks like it automatically looks in the /bin....
You can either place the DLL in the bin folder of the root of your application, or install it to the Global Assembly Cache (GAC) using gacutil (which requires the assembly to be strong-named and signed).
I would just keep it in the bin.
.net app looks in the /bin of the project, and the GAC (Global Assembly Cache) where you put system shared DLL-s.
If your app is one .net app (configured in IIS as one app), but you have aspx files in subfolders, they should see the root /bin folder. i'd stick with keeping dlls in /bin, if that isn't several tenths of bins (which would mean that you have a problem with your app organization).
GAC and bin are the only usual options.
You might also be able to configure your other folder as an additional bin folder, but I wouldn't hold my breath — this is from 1.1 and you still need to be within the same vdir as the main application.
Simply add the other dll's directories to your path environment variable. Must restart asp.net process / visual studio for the change to take effect. Worked for me.
that's the thing: because it's poorly organized (its a mix of asp and asp.net) it's certainly NOT configured properly....I think it's best to have "10 thousands bins" for now.
Thanks guys!