FirstCoreApps is a .net core empty web application..
when I am trying to add new web project CoreMVC it is adding a directory to FirstCoreApps as well, as shown in the screenshot.
I am very new to Asp.net core, please let me know what is the reason and how to deal with this....
When you created the second project, you seem to have accidentally created it inside of a folder in the first one.
This can happen if the solution (CoreApps.sln) file is in the same directory as the first project file (FirstCoreApps.csproj). The dialogs then probably suggested a directory that you should not have used.
Since the new project model automatically includes everything in the folder of the csproj file, the files of the second project automatically become part of the first project.
When creating new projects, be sure to check the "Create directory for solution". This creates a folder structure where the .sln file is created in its own folder and ever project in its own sub-folder.
Related
If we look at the settings page of a asp.net website project ( press alt+enter ) . It looks like this:
However, no where in the solution / website folder i can find out where these settings are stored ? there is no csproj file created for "website project" .
The reason I am asking this is because when I add the solution to github , and then clone on another machine, the references are lost and the project will not compile anymore. But if i copy the entire project folder to another computer, it compiles fine.
So for sure, there are some settings file that are not added to git repo.
Does anyone have any idea where these settings are stored ?
I will write down what I found later on for anyone's reference. The Contents in the reference list ( as pasted in the image above ) seem to be read real time from Bin folder of the project . So adding a dll file in Bin folder directly and closing/opening the Property page will show the newly added Bin file as reference.
There is a .sln file for website projects, just not where you might expect it. For Web Site projects, it is created in your default Projects location e.g. C:\Users\username\Documents\Visual Studio 2010\Projects\YourWebSite\YourWebSite.sln (or wherever you have your default Projects location set up in Tools/Options/Projects and Solutions).
I am new in mvc and c# and I can't solve following problem:
I am trying to create a folder named "Items" in solution folder.
I have tryed to use CreateDirectory method:
Directory.CreateDirectory("~/Images");
But it didn't work for me - folder wasn't created ..
Partly working solution was to create a folder by :
Directory.CreateDirectory(Server.MapPath("~/Images"));
"Items" folder was created, but it is not included in the solution:
How to create folder in solution directory so that it is included in project ?
(I needs to by done by code not by hand)
You need to understand what solution and csproj file is used for
In general, they're being designed and used for development with Visual Studio, and once the project is compiled, all these files will be ignored and excluded from the deployment package
Directory.CreateDirectory(Server.MapPath("~/Images"));
The code above simply create the directory if not existed yet in the deployment package at run-time, so you won't see it in your solution unless you run the project locally (either debug/release mode, it does not matter here). However, everything will run normally in hosted environment (ex: IIS).
For your information, here's the brief of what solution and csproj is
solution (.sln) file: contains information to manage one or many individual projects, contains build environments (for each project), start up mode (useful when you want to start multiple projects in one run), project dependencies and so on. Take a note that VS also read from suo file (solution user options) which is used to defined user-custom preferences (you should not include the .suo file in the version control, because it's custom settings)
csproj file: define the structures of project, what the namespace is, what is static folders, embedded resources, references, packages, etc.
Lastly, if you create the folder manually, VS will auto include that folder into deployment package AND csproj, but depends on the file type, you might need to change the Build Action and Copy To Output Directory in file properties.
Hope it helps.
A deployed web application on a web server doesn't have any notion of Visual Studio solution or projects. So the Directory.CreateDirectory(Server.MapPath("~/Images")) is the correct way to create a folder inside your web application at runtime but we cannot be talking about including it into a solution because this hardly makes sense in a pre-compiled web application. If you create the directory on your local development machine, you could always manually include the folder to the corresponding .csproj file, but at runtime this will not make any difference whatsoever.
The reason I wanted to create a folder (if didn't exist) was to make sure it exits before I try to store image in it.
After reading posts here and a few google searches I have concluded that the proper way to handle image upload would be
To create (In my case) folder "Images" by hand to be sure it exists
Then storing uploaded img in existing folder:
string path =Server.MapPath("~/Images/"+ UploadedImageName);
file.SaveAs(path);
I have an MVC Web API application created with VS2015 using the new preview C# 6.
The project by default comes with a Dependencies folder and a wwwroot folder. Both of these reside in the root of my project.
In the wwwroot I have an index.html which is trying to reference angular.js which can be found in the Dependencies/Bower folder (the actual path name is $(project_rootDir)/bower_components/.
So in my index.html I simply do:
<script src="../bower_components/angular/angular.js"></script>
When I start IIS Express and check what file the index.html is trying to load through console then I see it's trying to get it from:
localhost:5000/bower_components/angular/angular.js
But the path should be:
localhost:5000/../bower_components/angular/angular.js
But it seems like it cannot reference JS files from outside of the wwwroot folder. So I'm sort of stuck. What can I do? I want to reference the JS files from the Dependencies folder from the wwwroot folder.
EDIT: This answer relates to the new Asp Net MVC Core 1.0 in Visual Studio 2015.
Just wanted to update this as it's taken me a while to do this and google keeps bringing me back here. Short answer is you don't have to copy anything to anywhere.
#rdans answer is right in saying to look at the link (https://docs.asp.net/en/latest/client-side/bower.html) the most crucial element for this question is that to add a bower configuration file as soon as you create a project.
There is a .bowerrc file that also gets created which is what copies the newly installed bower components to the wwwroot folder (currently set to "directory": "wwwroot/lib").
You then have to follow the instructions to add the following code to the StartUp.cs file.
app.UseStaticFiles();
Then when you want to reference the file ensure you have a ~ at the start of the src url.
Hope this helps someone.
The files need to be copied to the wwwroot folder. I guess this should be happening automatically but I was having problems with this earlier as well. I followed the steps in this article to copy the relevent files.
http://docs.asp.net/en/latest/client-side/bower.html
The steps wernt exactly as described. Here's what I ended up doing:
Right click on gulpfile.js
Click on "Task Runner Explorer"
Double click on "Tasks -> Copy"
You should now see a "lib" folder in wwwroot with the necessary files.
I'm having a "tiny" issue with my App_Code folders.
I'm learning ASP.NET and, therefore, ordered a webserver with the support of ASP.NET 4.0. I'm using Visual Web Developer to program my webpages. When I upload my website to this webserver everything runs fine.
However, if I then add another web project to my server, my App_Code folder gets all messy. The server wants all my class files in the App_Code folder in the root. Is there any way I can create subdirectories in my App_Code folder or something to keep my projects organized or am I missing the point here?
You should take a look at codeSubDirectories in the web.config
Alright I found a solution to my problem. Although most of your answers might work aswell, this proved to be the best in my case. I created a subdomain and threw all files into that folder and it worked fine.
You should try to avoid using the App_Code folder for your own stuff, especially if you're using a web application project.
Whenever you convert a website to a web application project, the process actually renames your existing App_Code directory to Old_App_Code.
See Here, even though this is specific to converting .net 2.0 apps, I believe it still holds true in 4.0 since converting a 4.0 app does the same thing.:
VERY, VERY IMPORTANT: Because ASP.NET 2.0 tries to dynamically compile any classes it finds under the /App_Code directory of an application at runtime, you explictly DO NOT want to store classes that you compile as part of your VS 2005 Web Application Project under an "app_code" folder. If you do this, then the class will get compiled twice -- once as part of the VS 2005 Web Application Project assembly, and then again at runtime by ASP.NET. The result will most likely be a "could not load type" runtime exception -- caused because you have duplicate type names in your application. Instead, you should store your class files in any other directory of your project other than one named "app_code". This will be handled automatically by the "Convert to Web Applicaiton" command. This command will rename the folder Old_App_Code.
If you have access to a hosting control panel it's probably best to configure your hosting environment with a virtual folder for your second website and run it from the sub folder, e.g. www.example.com/project-b. The first site can still be running in the root folder, e.g. www.example.com.
So both sites will essentially be isolated from each other (just like they are now isolated as two separate projects in Visual Web Developer Express). And both sites have their own App_Code folder (and web.config file).
If you don't have access to a configuration panel, most hosting providers are willing to add a virtual folder for you, since it's really not a special requirement.
The virtual folder should show up as a regular folder in your FTP folder, usually inside the www or wwwroot folder. Now you can copy your project files into that folder.
Take care to use root-relative paths for URLs in your second project, so all links will work even when the website is run from the subfolder. Root-relative URLs look like this:
<asp:HyperLink runat="server" NavigateUrl="~/Default.aspx" />
<asp:Image runat="server" NavigateUrl="~/images/logo.png" />
This will automatically go to www.example.com/project-b/Default.aspx and www.example.com/project-b/images/logo.png when the website is deployed in the virtual folder.
If you need to re-use code from one site in the other, it's typically best to move such code into a separate Class Library project type, and then add a reference to that project to each website project (right-click the website project, choose Add reference..., then select the Projects tab and select the Class Library project).
I am running a CMS as an ASP.NET WebApplication and want to automatically include all files generated by the CMS in the project folder to be included in the project.
By default they are excluded, and finding them by hand and including them every time a new file is created is annoying.
Is it possible to include new files in the web application folder by default?
Web Site Projects work that way, however I am not sure why you would want CMS generated content in your source code repository.