Can you store start action / startup projects in project/sln files? - visual-studio

When I change a web application project's Start Action (such as Current Page, Specific Page, Don't open a page, etc.) and save, Visual Studio doesn't store this selection in a file that is likely to get checked in to source control such as csproj or sln. Likewise, if I go to solution properties and select several multiple startup projects and save, this selection is not stored in such a file either. Is there a way I can store this info in files that will get checked in to source control rather than user settings files?

These configurations are stored in the Solution User Options (.suo) file and they are not meant to be stored in source control, Microsoft Documentations:
The solution user options (.suo) file contains per-user solution
options. This file should not be checked in to source code control.
Startup Project, is a per user settings... a tester may want to set the test project for his startup while the developer wants the web project. The developer does not want his personal settings overwritten, every time he gets the latest version.
But, you can choose a default Startup Project, which would be used when there is no .suo file... to do this:
Open your solution file (.sln) in a text editor, you would see a list of your projects on top of this file, between Project & EndProject tags.
The first project in this list would become your default startup project, so you can reorder the project list and save your .sln file in source control.
Now if you delete your .suo file and reopen your solution in Visual Studio, the first project from the list becomes your startup project... and Visual Studio would create a new .suo file for you. I found this information on this stackoverflow post.

Related

In VS2010 the configuration list in Project Property Pages does not match the one in Configuration manager. How do I fix this?

I have an old Visual Studio 2010 Project with a lot of configurations. In an effort to refactor/make sense of the project I decided to shuffle around and re-name some of those configurations (Using the Edit option in the Configuration Manager). The problem? The list of the configurations available in the Project Property Pages (where one can change compiler or linker options etc.) still displays the old names! This can be very confusing and the lack of consistency is infuriating.
I tried restarting Visual Studio and deleting the .user and .sdf files - those didn't help. I even tried to manually Search&Replace the old names with new ones in .vcxproj and .sln files. The only result of that was being unable to open the project properly (does not build).
Is there anything I have done wrong? Can I do anything to restore some order into this project?
I suspect the behaviour I described is a bug in Visual Studio 2010 but I have eventually found a way to do what I wanted despite it.
In order to fully change the name of a Project/Solution Configuration:
Open Configuration Manager
Select <Edit...> from the "Active solution configuration" drop-down list
Change the name of the configuration you want to edit and close the Edit Solution Configurations window
In the "Project contexts" section of Configuration Manager, open the "Configuration" drop-down list. You will notice that the configuration which name you've just changed still has it's old one there. Select <Edit...> once again and change it to whatever you did in step 3.
Visual Studio will notify you in an error prompt that "The operation could not be completed". This is (partially) wrong.
Close the prompt, the Configuration Manager and finally close the solution (from the File menu) saving any changes to it.
Re-open the solution.
Go into the Configuration Manager and once again inspect the relevant "Configuration" drop down in the "Project contexts" menu. You will notice that although initially the old configuration name is displayed, the drop down figures only the new one. Select it. Otherwise attempting to access Project Properties will now generate another "The operation could not be completed" error.
The configuration should now function under its new name.

Creating an installer for Visual Studio 2010 solutions (one or more projects)

I ran into some troubles when creating an installer for my Visual Studio 2010 solution (which has multiple projects) so I thought I'd make a quick guide to how I got it working...
Here is how I did it:
Create a new Visual Studio Installer project which is located under
Installed Templates/Other Project Types/Setup and Deployment/Visual Studio Installer.
Make sure you add it to you current solution, you can do this by right clicking on the solution name in the solution explorer and clicking Add>New Project
From there select Setup Wizard, give it a name and click OK
A wizard will open, click Next
then select Create a setup for a Windows application
then click Next again. Select all of the groups you want to include, namely: Content Files, Source Files, Primary Output
Then click Finish
In the solution explorer you will see a bunch of buttons find the one that's tool tip says File System Editor and click it. You will see three folders in the file system editor, the only one we really care about is the Application Folder. That folder is where your projects build output should be.
To add files to it if they are not already there right click > Add > File...
Note: You cannot add entire folders (which sucks) and the folder structure in the Application Folder should be identical to that in your projects build.
You should create each folder and then add the files to it.
If you have multiple projects you should set the build directory to the same folder under the release build settings. To do this, open your solution, and for each project, right click/Properties go to the Compile tab, set it's configuration to Releaseand its Build output path to some folder (same for each project) (If you have an XNA project make sure its Content Build/Configuration is also set to Release).
Now select Release from the drop down menu on the tool bar (it most likely says Debug now)
Right click on your solution on the solution explorer and click Build Solution
Now all of your solutions built files will appear in the folder you chose in the compile tab. All of these files are what needs to be added to the Setup Projects Application Folder (in the same structure)
Customise the installer: click on the project name in the solution explorer and look through it's properties, change what you want (i.e Author, Manufacturer, Title - these make a difference to the installers output directory and text)
Build the installer project (same way as mentioned above) and you are done.
Feel free to comment with questions

Create Visual Studio Solution from Batch File

Visual Studio seems to consist of a single solution file (*.sln) along with one or more project files (a C# project would have the *.csproj extension).
I have been playing around with a console application that parses existing directory entries to create solution files with the associated project files.
It works, but every time I run into a new project here at work I find myself spending a week or more debugging my console project so that it can churn out a solution for that particular work project.
Is there something out there already that can create a VS solution out of an existing file structure?
As you can tell from my screen capture below, these projects are nested very deep, so it would take a very long time to do this with the apps folder below with the "by mouse" technique in the Visual Studio IDE.
I created the custom console application that is posted in this post:
https://stackoverflow.com/a/22153536/153923
I invite others to contribute how they approached this solution, though.
So, I found out today that this feature already exists in Visual Studio.
Link 1: How to: Create a Project from Existing Code Files
Link 2: How to: Create a Project from Existing Code Files
Basically, though, it says this (just in case the MSDN links get changed or deleted):
You can create a Visual Studio project from an existing app—for example, an app that you obtained from an online source. Project and solution files are created on your computer and the other relevant files are added. A project can be created from Visual C++, Visual Basic, or Visual C# code files.
Security note Security Note
We recommend that you determine the trustworthiness of existing code files before you import them into Visual Studio, because Visual Studio will execute some of the code in a fully trusted process when you open the newly created project.
To create a project from existing code files
On the menu bar, choose File, New, Project From Existing Code.
The Create New Project from Existing Code Files wizard opens.
Use the wizard to specify the details of the existing code files that will be added to the project and the application that will be created when you build the project.
Another good answer was given by cbp in Visual Studio: Create a web application from existing code:
--
OK I figured it out. It's weird, but the following steps will work:
Open fresh copy of Visual Studio
File->New Project, select Web Application
Use the following settings:
Name: Website (this is the name of the existing folder with the website files in it)
Location: C:\Temp\ (anywhere will do for now)
Solution Name: TheProject (name of the existing project's root folder)
Check "Create directory for solution"
Delete the auto-created Default, Global and Web.config files
Save All and close Visual Studio
In Windows Explorer, copy the new folder on top of the existing folder so that the files are merged.
Double click on the sln file to open Visual Studio again.
Select "Show all files" (at the top of Solution Explorer)
Right click on any files or folders you want to add and select Include in Project.
Great idea!

When I unload projects in visual studio, where does VS save this setting?

I checked the solution file and the project file, and can not find anything related to this setting. When people get latest version from TFS source control, they always see the 'loaded' status, which is not really what I want.
This information is stored in the solution user options file (.suo) which you can find in the same directory as the solution file. As the name implies this is user specific information which means sharing this across the team will be difficult because then everyone will need to live with the same options and store files in the exact location because the .suo file contains full paths.
For anyone else coming here with Visual Studio 2019, the unloading of projects is no longer saved in the SUO (at least in my experience). To save your unloaded project settings, you want to create a solution filter file (.slnf) which is the same as your solution file (.sln) except that it stores which projects you want loaded or not when opening the solution. Once created, you will double-click the .snlf file instead of the .sln file in order to load your filtered projects.
To create the solution filter file you can follow the instructions at this link or follow the summary below:
Open your solution (.sln)
Unload the projects that you want filtered out
Right-click on the solution from within the Solution Explorer
Choose Save As Solution Filter
Choose a location to save the file (I saved it right next my .sln file)
This will add the .slnf to your recently opened solutions list so you can either open from there going forward or navigate to the .slnf file and double-click it.
If you still want to see your unloaded projects after opening the .slnf, highlight the solution from within the Solution Explorer and click the Show All Files icon.
Base on this if you want to share your load/unload setting via source control you can use solution filter file which is .slnf extension.
So when you open the .slnf file instead of .sln file you will see the filtered project are loaded.
On MacOS with Visual Studio 2022 for Mac (i.e. v17.0 Preview, "Visual Studio Community 2022 for Mac Preview") I do not see either .sln nor .slnf files.
I observe that unloaded projects are saved in folder /.vs/[SolutionName]/xs/UserPrefs.xml. And when I close Visual Studio 2022 for Mac, I see that UserPrefs.xml is saved.
UserPrefs.xml Snippet:
<DisabledProjects>
<String>...</String>
</DisabledProjects>

Visual Studio: Set default startup project

I have a Visual Studio 2010 solution with several projects.
One of the projects is set as the default project, but I want to change that by default.
I know that I can right click the project I want to be the startup project and select "Set as StartUp project", but this setting will be stored in the user's files (.slo and .user files).
As a company policy, we don't check these files in the source control system, therefore when another user opens the solution it will have a different project as the startup object.
Is there another way to set these values? Something like a setting on the .sln or .proj files?
Thanks
From Arian Kulp's site, the way to change the default startup project for a solution is to edit the .sln file. You'll see some Project and EndProject lines. The first Project listed will be the default startup project, so just move the one you want to the top.
Follow these steps:
Choose the name of the project which you want to set default startup project
Click to the Project on toolbar and then click Set as startup project

Resources