I am trying to remote debug my asp.net mvc site on azure. I published my project in debug mode and then look into my remote website folders and it only shows 1 csharp file as opposed to all of them. I don't know why I can't see all of them.
Actually, it's interesting that there were any .cs files published. Assuming you published to Azure directly from Visual Studio, the MVC app gets compiled first and then deployed, and there shouldn't be any .cs files in the compiler's output.
From msdn:
The compiler produces executable (.exe) files, dynamic-link libraries
(.dll), or code modules (.netmodule).
Publishing in Debug mode doesn't change this. From msdn:
The /debug option causes the compiler to generate debugging
information and place it in the output file or files.
By way of comparison, all of the "static" files in your project (Views, style sheets, scripts, etc.) get deployed in the same directory structure as your project. But all C# files (Controllers, model classes, custom attributes, etc.) get compiled down to the executable, as quoted above, which then gets placed in the bin folder.
As an experiment, try publishing your website to your local machine and inspect the target folder. Assuming your solution contains only the one project (and assuming it's called GiantCorp.AwesomeApp.Web), it will probably be structured similar to this:
bin/
GiantCorp.AwesomeApp.Web.dll // <= all your C# classes compiled to a single executable
GiantCorp.AwesomeApp.Web.pdb // <= if you compile/publish in Debug mode
System.dll
System.Web.Mvc.dll
....etc for any required library or .NET assembly dependencies
Content/
bootstrap.css
Site.css
Scripts/
jquery.min.js
giantcorp.app.js
....etc
Views/
Home/
Index.cshtml
About.cshtml
AwesomeFeature/
Index.cshtml
Shared/
_Layout.cshtml
_ViewStart.cshtml
Web.config
Global.asax
Web.config
Related
I have more than 50 dll files in the bin folder in my mvc project. As someone who has just switched from web forms to mvc, why are there so many dll files. Only 2 files belong to me, K20.DAL and K20.BLL files. Are there any IIS configurations so as not to upload other DLL files to the server for each project?
All the other DLLs are present because they are referenced by your K20.DAL and K20.BLL project references. Few DLLs are part of MVC framework. When ever your application is running, only the DLL which is needed by your code currently executing will be loaded into AppDomain memory. This is on-demand-loading. After the code execution is over, the DLL will be unloaded from the memory. If some DLL which is needed by your code, but if it is not present, then your code breaks. There may be some shared DLLs also used by your application which will there in .net GAC assembly folder but not in bin folder.
So there is no harm to deploy these DLLs to server if you are not sure whether your application is using them or not.
Hope this clarifies your doubt.
I am trying to set up an ASP.NET MVC 5 project in Visual Studio 2013, based on another project I have been given by somebody significantly more experienced than me. In his project, there is a References folder, with references to System, System.Core etc., together with third-party libraries. However, this folder does not exist by default in my new ASP.NET MVC 5 project. Instead, I have a folder called bin, which looks similar to References, and I can add references to dlls. What is the difference between the References and bin folders? Why does his project have one, and mine has the other? Thanks.
Your references 'folder' are assemblies (DLLs) that are referenced by your project. The reference is held in text in the project file.
The bin folder is used for compilation of your project. At compile time, the references in the project file are resolved (located for use by your project when it's running). This may be copying them from another location on disk, downloading a nuget package or using a version from the GAC. If the assembly is going to be copied down from another location it will be copied into the bin folder where all the files necessary for the application to run are stored.
UPDATE:
A different project type had been added and hence the references folder was not visible. Adding an ASP.NET Web Project into the solution solved this.
In Visual Studio 2015:
File >> New >> Project (Web Application)
A Project will have a References node when viewed through Solution Explorer in the IDE. If viewed with a file explorer (Windows Explorer) there is no Reference folder. References are stored in the project (csproj or vbproj) file using plain xml/text.
File >> New >> Web Site
A Web site does not have the References node nor a project file. In Solution Explorer right-click on the Bin folder or the root node to add References. References can be seen in the Property Pages (right-click root node).
I have a Code folder in my asp.net mvc web project, I added a .cs file and the compiler does not seem to pick up any errors I make. However, if I first add the .cs file to the root of my mvc web project and then moves it to the Code folder, the compiler will work properly. Why is this happening? I'm using VS10 and mvc3. Thanks.
Edit: I notice I first called the folder App_Code and then renamed it to Code, so it seems if you add .cs to App_Code the compiler doesn't run on those, even if you move the .cs out or change the folder name to something else. Very strange.
From what you describing it sounds like the Build Action is not set to Compile on your file.
In response to your Edit. The App_Code is a special folder in ASP.NET, its files are compiled at run time. For more information see: Shared Code Folders in ASP.NET Web Sites
I'm using the publishing wizard and it published all of the necessary files except for my Controllers folder. I was under the assumption that I need a controller.
I have navigated to Package/Publish Web setting, do I need to tweak anything in here? I'm guessing this isn't set up properly out of the box. If I change the drop down to publish all files in this folder/solution will it try to upload all the referenced DLLs that don't need to be copied to the server?
In ASP.NET web projects, including MVC projects, .cs files (controllers in this case) are compiled into the /bin/[your.project].dll assembly when you do a Build or Publish.
So you don't need to publish/copy .cs files.
The controller and model code is compiled into the web site dll. The views are deployed in their folders.
This seems to be the only thing that works:
If a .cs file is inside App_Code...
And does not contain extension methods: set the build action to "Compile"; otherwise no other source code in the project knows of its existence.
And contains extension methods: set the build action to "None"; otherwise you get an error that the reference to x.Foo is ambiguous between MyExtensions.Foo and MyExtensions.Foo.
If a .cs file is outside App_Code, inside a folder called Helpers, it must have build action set to "Compile," regardless of whether or not it contains extension methods.
I don't understand this behavior. I wasn't sure that ASP.NET MVC contained any special privileges for App_Code, but it looks like it does... but only in the sense that it auto-compiles extension-method containing .cs files, even when the build action is set to "None"?? Someone please explain.
I'm assuming you've created a Web Application Project, not a Web Site Project. The App_Code folder in an ASP.NET application is special. It is designed to allow you to drop in code to have it compiled with the website in place. Because of this, the project items are marked as "None" to make sure they are not compiled by Visual Studio. When you publish a Web Site Project to your hosted environment, the code files themselves are copied in the App_Code folder, and this is compiled into a seperate assembly by the ASP.NET runtime.
Now, when you create an MVC Web Application, you must remember that it is not the same project type as a Web Site Project. An MVC Web Application will compile locally to an assembly in your /bin directory. If you add an App_Code folder to your project with your code in and you change the Build type to Compile, you run into problems because:
Your MVC application has compiled and includes a MyExtensions.Foo type and,
ASP.NET is compiling the App_Code folder which also has a MyExtensions.Foo type.
My recommendation is to avoid using App_Code. I tend not to, as I favour a more concise project structure. Use the Models folder for code, or create other folders.....
If you really want to use an App_Code folder, it might be better to mark the build action of any of the files as "Content" to ensure they are copied to the output directory when publishing your site.