Create a physical copy of a source file in Visual Studio - visual-studio-2010

In Visual Studio, if I try to copy a file from one project to another (by using Copy and Paste or by dragging the file to the new project while holding the Ctrl key) it creates a reference to the source file in the original location. Is there a way to create a physical copy of the source file and place that in the target project source direction without having to resort to using Windows Explorer to copy the file manually?

It's not pretty, but when I want to do what you're suggesting, I double-click on the file in Visual Studio, which opens it. Then I do a File->Save As, choose the right directory and save it. All from within Visual Studio. This is usually followed by adding the new file to the other project.
Was just doing this and realized I should mention a side-effect. Depending on your source control (in my case, TFS 2010), doing this from within Visual Studio may modify the location of the file in the project. For me, this means making sure that neither the file nor its project have any pending changes, doing the save as, then doing an undo of the change this causes in TFS 2010 (project change, file add and delete).

From http://msdn.microsoft.com/en-us/library/0fb6xxhb.aspx:
If you are working with solution items, Visual C++ projects, or other similar projects, you are always working with links in Solution Explorer. If you are working with Visual Basic projects, Visual C# projects, and other projects, you might be working with links or files.
Essentially, the answer to my question is 'No'. In most cases, I must use Windows Explorer.

Related

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!

Add reference deselected in visual studio 2010

I am trying to open a existing project in visual studio 2010 using
new->project from existing code
and selecting visual c# as the language. When I run it, I get errors. Later I heard from the person who created the project that I have to add few references, which are present in the references folder in the project itself. It comes in the side window - solution explorer.
However, when I right click on that folder to add as references, that option is 'greyed', or disabled. How Can I correct this?
The DLLs named freeglut.dll and glut32.dll are not COM or NET components. You cannot add them as references to your project (You have 4 solutions in your archive, I have choosen the one named fwa_annimate but I think the problem is the same).
The DLL named Tao.FreeGlut.dll needs these files in the same directory where you application run to work. So the easiest way to resolve your problem is to select the two DLLs inside Visual Studio and change the property Copy to Output Directory from Copy Never to Copy Always.
In this way, when you start to debug your app, the VS IDE will copy the two files to the BIN\DEBUG or BIN\RELEASE directory where you app runs when launched inside the VS IDE.
Of course, you need to deploy all these file when you distribute your application.
(By the way, I have no idea what is supposed to do)

How do I open a project without a .sln file in Visual Studio?

I was writing this program all in Vim and now I'm thinking of moving to Visual Studio, but since I didn't start in Visual Studio in the first place, there is no .sln file to open from. How should I open such a project in Visual Studio?
If you have a web project (without a .sln), you must do:
Menu File → Open → Web Site...
And choose the folder where the project is.
If a *.csproj file exists, you can build a new solution by Visual Studio at first. Next, you can open this *.csproj file in Visual Studio.
An even simpler way in Visual Studio is to follow this:
Menu File → New → Project from existing code
Choose the source file location and a .csproj and .sln file is created.
The simplest way to do this (assuming this is not a web project, as indicated in another answer) would most likely be to:
Create a new project (of the desired type), which should also create the solution for it to live within.
In the solution explorer, right click and select "Add > Existing item..."
Insert all individual files that belong in this new project.
It's probably also worth noting that it's a good idea to double check the project setting, namespaces, etc. before you get too far with building up your project to avoid potential issues later.

TFS View History in VS2010 for all files under a Solution

I'm trying to view history in Visual Studio 2010 for all files included in a given Solution file via the Solution Explorer View. I use TFS 2010 for source control, and I'm aware that I can get history for a folder recursively in Source Control Explorer. My issue is that we have multiple projects in a root directory, all of which are included in a variety of solution files in that same directory (each solution file represents a deploy-able component, including some "shared code" between them). I just want to view history on all of the files included in a given solution file, and not everything in this root directory. When I right click on a solution or project in Solution Explorer and "View History", I just get history for that solution file or project file, nothing more.
Alas, this cannot be done with TFS as it is.
TFS Source control does not know if a file is a solution file or a text document. It just stores it for you. There is no parsing at all. I can (and do) store Delphi project files in TFS. There is no way for TFS to be able to understand and be smart about every file type that exists.
It would be nice if Solution explorer did this for you (as it is specific to your project). But it does not.
You could create a custom plugin to TFS and Visual Studio to do what you are asking, but it would probably take longer than just manually checking the history of all the files in your solution.
This might help, it's an add-in extension
VS 2010 and VS 2012

Visual Studio 2010 - .Sln file when clicking on .csproj

I can open my project by double clicking on the .csproj file. It opens fine and it doesn’t generate a .sln. If I copy the same project to a virtual machine and do the same it opens but creates a .sln file.
I really don’t need a solution I would prefer to only work on a single project.
Am I missing something here?
Visual Studio always creates a solution. If it cannot find one in the same folder as the .csproj file then it will create one itself, based on what it can reverse-engineer from the project file content.
The solution is hidden by default if the solution only contains one project. Fixing this is recommended: Tools + Options, Projects and Solutions, General, "Always show solution" checkbox.
There is always a solution, even if you don't see it. There's a setting that determines whether the solution is visible when there is only one project.

Resources