Edit
I just downloaded the source code of the tutorial project from GitHub. When I build and run the project, I see that the Website/Modules/ folder is copied into the bin/Debug folder of the Service project. But this does not happen when I build my Service project.
What could be the reason?
I am following the tutorial in this link.
I have completed the part until the index.html is added and should show Nancy is working! when the webpage is loaded.
I had to change the ViewLocationConventions to
$"../../../Service.Website/Website/Modules/{context.ModuleName}/views/{viewName}"
Only then everything works fine with Nancy 1.x version. Why doesn't it work when I use
$"Website/Modules/{context.ModuleName}/views/{viewName}"
like in the tutorial?
And when I use Nancy 2.x, it cannot find the view file at all. No matter what I set ViewLocationConventions to.
i.e., it still looks for the Website/Modules/Root/view/index.html file in the Service project.
Any other workaround, other than moving the view files itself to the Service project?
Quick background of the tutorial:
The solution has 2 projects Service and Service.Website as shown below.
Service is a Topshelf service that hosts a server that runs the web project
Service.Website is a web project using Owin and Nancy
Thanks to #hellyale's comment, I had to set the Copy to Output Directory of the index.html file to Copy always.
This then copies the file to the bin/Debug folder and Nancy is now able to find the view.
Related
I have finished a very basic application (wpf/c#). The solution is made of 3 projects:
The main project for the app
The Class Library Project to store app resources (images and txt files)
The Setup project which I use to create exe file for distribution to other
machines.
While the project works fine in debug mode when I deploy it using the Setup project and install on the computer I can access the image files from the Library Project (I can see there is a dll file for the library project in the application folder) but it fails to access the text files, complaining the path was not found. This is my very first time I completed the application and attempted to deploy it so am a bit at a loss why the setup does not provide correct references to the text files and yet it seems to work fine with image files which are located in the same library project.
Can someone point me in the right direction where to look at it to troubleshoot?
I have cleaned and rebuilt all projects in the solution. retested in debug mode (works fine). tried to search msdn and StackOverflow but I cannot find any guidance I could use or follow.
I would like to be able to display text from the text files in the released/installed application version the same way it works in debug mode. At the moment it fails to find the relevant txt files.
Finally, I have managed to crack it. Posting the answer for anyone having the same problem.
The issue here was not with the file path, even though I came up with a more clearer technique of building it, see my comments above. The problem was with the way Setup Project in VS2017 was creating a package. It is handling differently images and text files, even though both are in the same Library Project, essentially for text files I had to do the following to get it working:
Open File System in Setup Project
Create the 'Resources' Folder under 'Application Folder'
Set the 'Resource' folder 'AlwaysCopy' property to 'true'
In 'Resources' folder right-click and select Add> File...
Navigate to the folder with the files and select them all (make sure the files are setup as Resources or embedded resources)
Rebuild the Setup Project
.
So summarising I had to specifically tell Visual Studio to build the folder structure in the Application Folder during the install.
Now when I run the installer the text files are included in the package and created during standalone installation. Also included a screenshot below.
So this is something that I expected to be simple, but I am not sure what is going wrong.
I am working on a C#, ASP.NET Web API project, and I am trying to set a content path to some folder in the solution's root directory.
For some reason, no matter what I set the Working directory option to under Properties > Debug, printing out Directory.CurrentDirectory() in my applications startup logic is always the default (somewhere in the bin directory for that project). I tried using $(SolutionDir), but found that is not supported in C#. I then tried some relative paths and absolute paths but nothing is working.
Am I missing something here? Is this setting just not used for C# projects or does it have something to do with it being a ASP.NET project? I found other questions on here asking how to set the current directory, but the answers were to use exactly the setting I have been using.
I know I can technically just change where the build executable is located, but that seems like an ugly work-around when the logic of the application already uses the working directory.
EDIT: Some more details in response to some comments.
So the premise of this project is it is a C# Web API that serves as a backend for an angular app. The angular app is built separately into a zip file which is then stored in the resources of the C# program. Upon running, the files are extracted and served on localhost for client machines. When the program is run in debug mode, however, it just sets a root content path and serves the raw files for the angular frontend. My goal here is to remove some manual configuration in debug mode as to where the angular frontend is is on disk. It is checked into the root of the solution directory, so I am trying to set the current working directory for debugging to the solution directory, and then the program will just be able to work normally when being debugged from Visual Studio.
I hope that isn't confusing things further.
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 have several ASP.NET web projects and their Output folder are set to "C:\Builds\[ProjectName]bin" (instead of the default "bin\" folder). This makes "F5" Debugging not working because the ASP.NET Development Server expects the "bin" folder under the project folder.
I then changed to use Local IIS Web server (http://localhost/webproject1") and manually updated the vdir physical path to my custom output path. However the VS2010 will not load the csproj because it detects the url is already mapped to a different folder location.
I know I probably shouldn't change the Output folder. But wondering if there is an easy way to workaround this? The goal is to make "F5" debugging work with custom build Output folders.
Update due to Aristos' answer:
Thanks Aristos. Unfortunately that won't solve the problem. All my projects already use the Project Reference, so all the reference dll's are correctly copied to the output folder. The reason why F5 debugging does not work is because the output folder is not the normal "bin" sub folder, but in some other path say C:\BuildsOut\Foo\bin.
It seems that in order to use F5 to debug the web project in VS2010, it has to use the default Output path "bin". If you change that, then F5 will not work and even worse your project may not even load.
Ian,
I have been frustrated by the same problem. I finally gave up and put this dirty little fix in place. I added the following to the "Post-Build" event:
copy "$(TargetDir)MyWeb.dll" "$(ProjectDir)bin"
copy "$(TargetDir)MyWeb.pdb" "$(ProjectDir)bin"
This at least lets me debug the site properly and hit my breakpoints.
You place them all on one single solution, you set as the started project your web project, and then you add on your web project the rest dll as reference (right click on web, select on menou "add reference", and automatically gets the latest version of dlls and place them on bin.
Now when you ress F5 if anyone dll project needed is automatic build it, then run the subproject with the new dll inside.
Delete all items in your bin folder for the solution in question, shut down your system and restart. This fixed it for me at least.