In my Visual Studio Solution, I have a Website project, as well as a Web project (the latter a Class Library containing things like web-specific logic, HTTP handlers, etc.)
I would like to include shared static assets in the Web project like JavaScript and HTML template files. These files will be referenced and used in the Website but may be used in one or more other projects in the future, so I would like to keep them in a common project. Ideally they'll end up somewhere like /js or /templates in the Website. I'd prefer them not going in the /bin directory if possible, but I could be convinced that it's fine.
That said, what would be the most appropriate way to keep them in the Web project, but have them deployed with the Website at build/run and deployment time, whether debugging from Visual Studio or building with Jenkins/MSBuild? The options I see are "Copy to Output Directory" or some sort of embedded build action (not ideal, as I would like to copy the files into the output directory in their native format.)
Related
In order to debug Web API projects in Visual Studio 2013, I had to set output path for the Debug configuration to bin\ (meaning files end up in {ProjectName}\bin relative to the solution root folder) as can be seen from some of the answers here.
But now I face the issue that we have used the path bin\{ConfigurationName} in several places in our build server setup. I would very much like to unify the setup for Debug and the other Visual Studio configurations.
Therefore my question is: do you know of any problematic consequences of unifying the output folder for all configurations to be bin\, leading to folder structure {ProjectName}\bin?
If you do, is there any way to debug a Web API project without changing the output folder from bin\Debug\ ?
No Consequences:
By default, Project builds are stored in Project directories like:
{Solution}/{Project}/obj/Debug/{Project}.dll
{Solution}/{Project}/obj/Release/{Project}.dll
A folder for each build type in each Project folder
If all your binaries were output to the same directory, they would
link the same way at run-time in your development environment
resolve dependencies the same way
deploy the same way
The result would be directory structure of
{Output Directory}/Debug/{Project}.dll
{Output Directory}/Release/{Project}.dll
The IDE is customizable:
There is no requirement to keep Project builds in Project directories. Project build Folders are a configuration default. The IDE was designed to allow you to work around your comfort zone. If you prefer to group all assemblies, or find that it resolves an issue, you are free to change this build configuration.
Problems De-bugging Web-API?
You should not have to change the output path to Debug Web API. Attach your Web-API to a worker process.
1) click on your Web API Project in VS Explorer
2) click debug in Visual Studio Menu
3) click Attach to Process...
4) click / select all processes named w3wp.exe
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.
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.
I have a Visual Studio 2008 solution with an ASP.NET Web Application project. I want to change the default output folder, of said project, to $(SolutionDir)\WebApps\$(ProjectName)\bin. This I can do and when I build I get the expected assembly files in this folder. It doesn't copy the content files (aspx, etc.) to the parent folder but I have managed to fix this by hacking the project.csproj file with a custom build target.
The problem is I want to be able to debug this application using the ASP.NET Development Server, by pressing F5 in VS2008. Unfortunately the ASP.NET Dev server starts, has a "Physical Path", in the project directory rather than the parent of the output directory.
Is there any way to build my web application to a different output folder but still run the asp.net dev server to debug my site?
Thanks.
Short answer is yes, but it isn't pretty. The process I used is given below.
Unloaded the project in VS.
Manually edited the .csproj file to include a post build action that basically copies the content files (aspx, etc.) to the parent of the output folder.
For the debug options I set the project to launch an external executable. The Asp.Net Development server. Also manually set the url to launch.
What I learnt? I wouldn't do this, I'd just stick with the default and create an install/web deployment project instead.
I have a C# application that uses several web services which were added to my project as web references. I want to know what files i should check into source control.
in my project there is a folder structure from my project directory that looks like this:
Project
Web References
WS
WS.wsdl
Reference.cs
Reference.map
...misc .datasource and .xsd files
Which of these files should i put in source control?
Thanks
Suggest keeping all those files under source control, but only for completeness for other developers using your project's source code, or having to perform a Checkout/Get Latest on any new machine (after your dev machine's hard drive dies, etc.).
Once Visual Studio builds the web reference, all those files are built and remain unchanged until you 'Refresh Web Reference'. If you modify them yourself, i.e. change a datatype, or remove an XML attribute (I've had to do that for some obscure runtime SOAP problem), then check those changes in as well.
If your nant script or visual studio solution or what have you rebuilds any particular files on each build, then don't check those in, as it'll just lead to confusion. Otherwise check it all in.