Create Project/solution in an existing directory?

2019-03-14 16:39发布

问题:

How can I create a New project & Solution in the same, existing , directory? No matter what I do, it keeps creating a new (sub)directory for the project and populating that directory instead of the one(s) that already exist. I have the "Create directory for Solution" checkbox cleared so that it will put the solution an dproject in the same folder and not create a solution folder, but it still keeps making the project sub-folder.

How can I fix this?!?

This has bugged me for a long time, but I've been able to ignore it or work-around it up until now. But now it is kicking my butt productivity-wise on my customer project and I need to fix it. thanx... RBarryYoung

(Note: This is VS2005, Team Edition for Software Developers)

回答1:

From Visual Studio, if you have no solution open, you can select

File->New->Project From Existing Code

Select the project type

Put the directory you want the solution and project file to be in as the "Project file location" field.

Finish the wizard and you'll have a project file and solution file in the same directory.

If the "Project from existing code" option is not available

Make a custom keyboard shortcut, toolbar button or menu item by using the customization features of VS.

Tools->Customize

Select the "Keyboard" button to add a keyboard shortcut or select the "Command" tab to add a toolbar button or menu item. The command you are looking for is:

File->New Project From Existing Code

Assign whatever keyboard shortcut or drag an icon to whichever menu/toolbar you want.



回答2:

To create a solution in an existing directory, I have found the best way is to create it one directory back from where you actually want it, then use the name of the directory where you really want it as the name of the solution.

If that isn't the name you want (i.e. you don't want your solution name to match the name of the directory it is in) then once you have created it, you can rename the solution by right-clicking on it and choosing "Rename". It does not rename the directory it is in nor move it. That is by far the simplest way.

You can obviously use the same trick for a project too, however if you have more than one project in a single directory, ideally the intermediate directory into which they build should differ, otherwise you are going to have issues if you want to rebuild just one of them and it clears out the intermediate target directory.



回答3:

You can always move things around manually and edit sln file to fix the project references. For example, if you want your solution file to be in the same directory as the project file, you can cut the solution file from wherever it is and paste it into the project file directory. Then you need to edit the solution file to fix the project reference so that the solution can find the project when it is opened.



回答4:

I don't know of any out-of-the-box solutions for you. But, if the code files are organized into folders according to the wanted structure you could hack together a tool to do it for you, perhaps. The project files are not awfully complex in their structure, they are rather straight-forward XML documents, largely consisting of a list of the files that are included in the project.

I would assume that the resulting project files may still require some manual labour, but you should be able to get the code to do the heavy work for you. And you may get a nifty tool to post on your blog.



回答5:

  1. Open an existing project. If you don't have one yet, create a temporary one.
  2. Select "File" > "new" > "Project"
  3. Make sure "Create new Solution" is selected
  4. Choose the type of project you want.
  5. Press Ok to create the project

If you created a temporary project in step one, you can delete it now

-> now you have created a project where the solution file is within the project