Create Project/solution in an existing directory?

前端 未结 6 1359
南方客
南方客 2021-02-04 00:03

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

相关标签:
6条回答
  • 2021-02-04 00:25

    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.

    0 讨论(0)
  • 2021-02-04 00:25

    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.

    0 讨论(0)
  • 2021-02-04 00:35

    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.

    0 讨论(0)
  • 2021-02-04 00:41

    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.

    0 讨论(0)
  • 2021-02-04 00:44
    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

    0 讨论(0)
  • 2021-02-04 00:51
                public static class SlnFileGenerator
                {
                    #region Public Methods
                    public static string GetBatFileContent(string directoryPath, string slnFileName)
                    {
                        if (directoryPath == null)
                        {
                            throw new ArgumentNullException(nameof(directoryPath));
                        }
    
                        if (slnFileName == null)
                        {
                            throw new ArgumentNullException(nameof(slnFileName));
                        }
    
                        var sb = new StringBuilder();
                        sb.AppendLine($"dotnet new sln --name {slnFileName}");
    
                        foreach (var csprojFile in Directory.GetFiles(directoryPath, "*.csproj", SearchOption.AllDirectories))
                        {
                            var relativePath = csprojFile.RemoveFromStart(directoryPath);
    
                            sb.AppendLine($"dotnet sln \"{slnFileName}.sln\" add \"{relativePath}\"");
                        }
    
                        sb.AppendLine("pause");
    
                        return sb.ToString();
                    }
                    #endregion
                }
    
    0 讨论(0)
提交回复
热议问题