Open a csproj and not the entire solution - c#

I am working on a solution that contains 30 cs projects. I am focusing on only 1 project so I preferred to open only this specific project.
Once opening this specific project, it loads the entire solution wiht all the others 29 projects.
Is there a way to open only this specific csproj?

The following structure can be used to get the desired behaviour:
Create a new Visual Studio solution
Delete the created default project
Add an existing project to the solution
Set the project as startup project (for re-build etc...)
You are now ready to go

You can do this in minutes and it's quite simple. Each sln file contains a number of projects that are written in this form :
Project(...) = "name.of.the.project", "{unique identifier of the project}"
and below that are the configurations for that project.
So you can write a javascript file to copy your original sln into each project folder found in that sln. After that iterate through each project folder and for each sln remove other projects. The javascript file can be runned using a .bat or cmd.
In this way you can assure that each project of your solution has inside his folder a new solution that contains that project.

We have a solution at work which has hundreds of projects.
So what we have done is have a Main.sln which contains everything. Then were have broken up the rest of the projects into different smaller solutions where they are grouped by relevance.
ie. All the database projects are in one solution, UI projects in another etc.

Related

VS intellisense not working on solution with multiple projects

I am working on a .NET Core/C# solution that contains multiple projects. I have done so before but for this one I set up everything through a remote server in a linux terminal. Once all my projects were created and pushed to GitHub, I pulled to my local machine. Problem I am running into is that intellisense is not working at all in any project in my solution. I am wondering if I set up everything correctly or if there is something I am missing. Below is some screenshots of my directory and one screenshot of VS.
root dir from repo
1 dir down into BlabberApp folder
2nd dir down into BlabberApp.DomainTest
What is shown in VS when I open root dir
What is shown in VS when I open solution file
I have tried opening using open file for: .csproj file, .cs file, as well as open folder for various folders that hold my separate projects. I also tried to open folder to the BlabberApp folder which contains the folders that hold my .sln as well as the folders that hold all my separate projects. I need intellisense to recognize references some projects have with each other. I also need it to recognize my tests to properly test everything. One thing peculiar I found is when I open the .sln file it shows in the solution explorer that 0 projects are loaded. Also none of my tests are recognized in the test explorer (I have tried cleaning and building the sln with no changes showing in test explorer).
I have also gone through the steps of going to tools -> options -> text editor -> c# -> intellisense to check/uncheck the boxes under completion lists. Any advice would be helpful! Thanks
It seems any of your projects are not listed in your solution. Somehow they unloaded from the solution. You can add the projects one by one in the solution. Or you can take help of a plugin that will add all projects from the solution folder at once. please add them by the following step:
Add this VS extension
Right-click on the solution and click on Add multiple projects
check Add solution folder
Click Load Projects From Folder
Select the solution directory
Select all projects
Click start
please follow the link instructions for more details.

Taking sln file from other app

I worked on some C# app (wpf), I uploaded it as zip file to google drive for now that's the only copy of the project That I have.
The problem is that I forgot to upload the .sln file.
When I downloaded the app from google drive to my pc I took some other .sln from other app and it worked fine for now.
Is it ok? I mean it can cause any problems in the feature?
A solution is sort of like a container that holds all your projects together. So as long as you have a valid project file (.csproj) you can simply create your own solution file and add the project to it.
If you go to:
File > New > Project
you can open up New Project dialog box.
There, under:
Installed > Other Project Types > Visual Studio Solutions
you can create a blank solution.
Once you do that, then you can add your existing project to this new empty solution.
For that, go to your Solution Explorer, right click the solution and select Add > Existing Project and select your project.
I took some other .sln from another app and it worked fine for now:
Most of the time: If you have a single csproj file, all you have to do is double click on the csproj file to build it. Visual Studio will automatically create a solution for your single csproj.
Is it ok? I mean it can cause any problems in the feature?
I think the big issues will only come when you have more than one project in your solution.
For example, lets say you have a solution with Project A and Project B, and project B has a reference to A.
You will need to add both projects to your new solution so that .NET knows to build A first, then build B using the output from building A.

Visual Studio Project rearrange project into folder with same name

Project name is testProject. I want to create a new folder named "TestProject" and move the project into it, because I want to add testProject.uTest and testProject.iTest for unit and integration tests. So everything related is located in the same folder.
The solution is in VSTS. Already one folder exists with the same name because of the project. Namespaces will all change.
How do I go about this the best way?
I got everything to work.
First I opened the solution and deleted the project in there. Then I created the new folder in the solution explorer. I then copied all the project related files into the new folder in windows explorer. I opened up the solution and added this existing project and add all files to source contrl. Next I had to re-add nuget packages and fix some references in other projects. Next I pushed the changes and then I deleted the old project files in source control explorer.
Took 10mins and everything works fine!
A few simple steps that worked for me:
Create a folder and add some text/number at the end:
Example: Infrastructure1
Create/Add the Project to your solution without the text/number at the end.
Example: Infrastructure
Rename the folder (Infrastructure1) to match your Project name(Infrastructure).
That's it, and you will get rid of the message that Project can't be named with the same name as the folder.

.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.

.Net folder compilation tool

I have a folder with many .csproj files. I have many folders like this.
I have a big solution with all my projects in it, but most of the time i just want to compile all the projects in one of the folders.
Is there a tool that I can use to let's say right click on the folder-->"Compile all"?
Did You try Building the Solution that contains all the projects?
Either:
Select all of the projects in the solution explorer that you want to build, right click and select "Build Selection"
or
Add a/several build configuration(s) that only builds the projects that you are interested in
or
Create a new solution file with the projects that are grouped, which will only build those (the solution file can exist in the same location as the current one)

Categories