Upload without cs files - c#

I created a ASP.NET MVC project on one machine, when it came time to upload to the server, I'd just copy the Views and the Bin folder, no Controllers or Models.
However when I copied the project to another machine, the Bin folder is not being updated with a new compiled dll so I can't just copy the bin folder.
What setting do I need to tell VS2015 Community to compile the Controllers so I only need to compile the Controllers and copy just the bin folder?
Admittedly, I should've mentioned it was an ASP.NET rather than a desktop application.

It looks like what I had to do is make the site into a Web Application and there's no easy way, if there were, it'll be found at Microsoft site which the closest I found to the answer is :-
https://msdn.microsoft.com/en-us/library/aa983476.aspx
I created a new project and then copied the files across to the new one. Unless there's an easier way, thats the only solution.

Related

Why can't I see the Controllers folder within my deployed MVC web app directory?

I have recently purchased a shared web hosting package, provided by GoDaddy, and deployed my own MVC web application to it.
My problem is that, when on the control panel (Plesk) provided by the host, I can't find the Controllers folder that contains all the behind code.
Is there a reason for this folder being hidden?
I'm guessing it's because the files within this folder are being used by the server all the time and can't be accessed/changed incase it f--ks everything up... But I am not sure about it because I am quite new to web hosting.
Thanks for any assistance in advance.
All your cs files including controllers will be compiled into DLL files. Please open "bin" directory to find all your DLLs.
When you deploy, u ll not get controller, because it contains c# code which changed to dll available inside bin folder.
Not Only Controller, the other folders which are having C# code like "App_Start"...and etc...will be changed to dll and will be available inside bin folder.
In the case of Model/s, if you are using Entity framework, then, the .edmx file will be available inside the Model folder.
All your Business logics including controllers, models and core etc are converted to dll and by Assembly name dll is created in bin (released or debug folder)

Can you have multiple APP_CODE folders in a project

I inherited this code from another developer (3rd party) but I am implementing it. Its a large website done in c#. For twitter integration they must have created a new website project because the code inside the sub folder has its own bin and app code folder. This is published on IIS but its a strange setup where it compiles at run time. (If I make a code change to a file on the webserver and save it, it updates instantly without having to publish).
This subdirectory is throwing a 500 error and I assume its because I dont believe you can have multiple bin and app_code in the same website project. Is that a correct assumption. Should I combinbe all the app_code directories to the one in the root? Here is a more visual example of the directory layout:
MyWebsite
App_Code
BIN
...other folders and files
MySubdirectory
App_Code (ALLOWED??)
BIN (ALLOWED??)
App_Code and Bin are special folders only at the root of the application. You should make MySubdirectory a child application in IIS.

Intellisense missing in App_Code, for bin dlls in Website Project

Any classes I create in the /App_Code or /App_Code/[subfolder] don't have local intellisense.
That is - I have intellisense for system dlls such as string.[member] etc. But cannot get it to recogize any classes local to App_Code (including itself), or dlls referenced in the /bin folder.
Although I do have intellisense of inside the scope of a member-function. (ie. local variables or function parameters)
NB
This is a Web Site project, not a Web Application project.
I have tried resetting all the Visual Studio settings and clearing the intellisense information found in AppData for VS.
Im working with Visual Studio 2012 ver. 11.0.61030.00 Update 4
The project is using .NET 4.0
If I move the classes outside of the App_code folder, they register in intellisense perfectly.
There is no option to set the Build setting of the files to Compile as this is a web site project rather than a web app.
IMO, you should move your code out of App_Code. In .net 4.5 (and 4.0) your behind code is compiled to a dll, so I don't see any benefits to putting your code in App_Code. If someone advises different, I am interesting in hearing.
With that said, create a folder or folders under your root project and put your code in there.
MyWebsite
- DataLayer
MyDataLayer.cs
Default.aspx
In this example, you will be able to access your classes DataLayer.MyDataLayer
Even better create a new library for code that is not needed in your aspx.cs code behind files.
New code files in App_Code will have the build action "Content", hence you got no intellisense.
So right click your code file and click "Properties", in the property window change the "Build Action" to "Compile".
Then reopen your code file.

.NET (Visual Studio) Share assets between projects

I'm working with Visual Studio. There I have a solution with several web-projects (.net MVC 4). All of these web-projects use the same javascript-libs. Currently I copied the library into each project, but this can't be the final solution. What is the best approach to share those library (assets in general) between all of the projects? Just link them? Or is it possible to create a project and reference it in all projects?
Update
"Link" the javascript files from another project is not a possible solution as I would have to link thousands of files (one of the libraries I am using is ExtJs) what makes it impossible to build a project without freezing visual studio...
Possible solution
Currently I have a (Web) MVC Project called "Web" and a (Class Library) Project called "ClientScript" which contains all the JavaScript files which are shared between several Web Projects. As linking all the needed JavaScript files is not a possible solution (because it's a matter of thousands of files what causes visual studio to freeze) I copy all the needed JavaScript files to the individual Projects using the Build Events in each Web Project (Project -> Properties -> Build Events -> Post-build).
My Post-build command line in the Web Project looks like this:
start xcopy "$(SolutionDir)ClientScript\Frontend\*" "$(SolutionDir)Web\Scripts" /r /s /i /y /D /E
Every time you build your Web Project all the changed Javascript files get copied from the ClientScript Project to your Web Project.
While developing the Javascripts I run a small "filewatcher" tool which automatically copies a file from the ClientScript Project to every Web Project when it changes. This way I don't have to build the Web Project every time when I make a change to one of the Javascripts.
Anyone that stumbles across this question here in the future should know that there are now Shared Projects in Visual Studio to solve this problem. Universal Windows projects use them by default and you can create your own by downloading and installing the VS extension here: https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450
Note: At this time they can be picky about what type of project you try to add the shared reference. I created a JavaScript shared project to share js files between a Windows store js app and an MVC web app and it would not let me do that saying they had to be of the same language. (It supports C#, C++, or JavaScript).
Place the JS files in a single folder, likely above all others, and add them to the project but use the "Link" option. It's part of the drop down on the "OK" button in the "Add existing item..." dialog.
When you run every new ASP.NET MVC 4 project it's take a new port then other app have take.
I simply suggest you a simple thing.
run a project which contain all the pacakages. open them webmatrix and run them as localhost:80.
You need to set the port in settings section of your site in webmatrix. Now it will rechable at localhost now you can reference all the libraries from this packages.
Slightly older thread, but I have another way of doing a similar thing using Web Essentials, that handles the issue of not publishing correctly.
I have a shared folder outside of the projects that require the shared file, normally a 'common' project with other things in as well, but can be just a simple folder as suggested by Michael Perrenoud.
However instead of 'Add as Link' I have been creating a new bundle in the project that requires the shared js/css file, with the same name as the shared file, and then referencing that file in the shared folder using a relative reference location rather than the root based one it starts with.
To add a file from a shared folder in the root of the solution to the scripts folder use the following code in a new bundle file (*.bundle), changing the folder/file names as required.
<?xml version="1.0" encoding="utf-8"?>
<bundle xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://vswebessentials.com/schemas/v1/bundle.xsd">
<settings>
<minify>false</minify>
<runOnBuild>true</runOnBuild>
</settings>
<files>
<file>../../MySharedFolder/my-js-file.js</file>
</files>
</bundle>
Then every time you build it recreates the bundle with the latest version, this version is then also published as expected :)
You can even create a minified version if desired by changing 'minify' to true. Or better yet you can add them loads as a bundle too if you want, you have that flexibilty.
This is an older thread but due to complex business requirements these days applications are divided in to different modules or sub projects.Thus, brings us the need to share common resources like JavaScript files, themes and CSS style sheet files.
I personally feel that common files should be put in separate Asp .Net MVC 5 project which has following structure :ASP.NET MVC5 folder structure
Now the best part is you can separately manage the dependencies using Bower,NPM or Nuget package manager.
After you have organised all the files in this project host this project to your own CDN or may be on cloud. You can use Using CDN in Bundle Approach to get script or link references.
That will help you sharing common resources across all the projects.There us a short coming though if you have many developers on the team and if someone added incompatible version lib can affect all the apps.

ASP.NET MVC Global Resource File deployment

In my mvc3 web project I have an App_GlobalResources folder containing the resource file Permissions.resx.
I am able to access the values in this file when I run the site locally in visual studio using:
string value = (string)HttpContext.GetGlobalResourceObject(resourceClass, key);
However, once I deploy it to the production web server it is not able to access the values in this file. I checked and it is creating App_GlobalResources in the bin folder of the publish directory containing the file.
My first time using global resource files, is there any additional steps required to get this working once deployed to the webserver?
Thanks.
I'm pretty sure App_GlobalResources should not be created in the bin folder. Have you got Copy to output folder set? (You shouldn't need it).
In WebForms, in properties of the .resx files, we have Build Action set to Content and Custom Tool set to GlobalResourceProxyGenerator. This creates dlls for the resources in the bin folder.
However, I've not used App_GlobalResources in MVC (it makes things tricky to test outside of a web context), but there's some info here that might be useful:
http://odetocode.com/Blogs/scott/archive/2009/07/16/resource-files-and-asp-net-mvc-projects.aspx

Categories