简体   繁体   English

如何在ac#project中最好地改变目录结构(sln和项目)

[英]how to best change directory structure (of sln and projects) in a c# project

I'm working on ac# project, lately we decided to restructure the directories structure of the source code. 我正在研究ac #project,最近我们决定重构源代码的目录结构。 I'm doing the restructure and wanted to ask you some questions about what is the best way to conduct the change. 我正在进行重组,并想问你一些关于进行变革的最佳方法的问题。 The restructure is basically changing the current directories of all the projects to a more structured and logical order. 重组基本上是将所有项目的当前目录更改为更结构化和逻辑顺序。

The current structure is (this is a scheme): 目前的结构是(这是一个方案):

  • Main Dir: 主要目录:

    • Project 项目
    • Project 项目
    • Dir 迪尔
      • Project 项目
      • Project 项目
      • Project 项目
    • Dir 迪尔
      • Project 项目
      • Project 项目
      • Project 项目
    • Project Dir + solution file 项目目录+解决方案文件
    • Project Dir + solution file 项目目录+解决方案文件
    • Dir 迪尔
      • Solution file. 解决方案文件
      • Project 项目
      • Project 项目
    • Project Dir Etc.. 项目Dir Etc ..

The Target scheme is: TFS Project: Main - Source - Dir - Solution file. 目标方案是:TFS项目:主要 - 来源 - 目录 - 解决方案文件。 - Project - Project - Project - Project - 项目 - 项目 - 项目 - 项目

     - Dir
        - Dir
            - Project
            - Project
            - Project
        - Dir
            - Solution file.
      - Dir

        - Project
        - Project

The relative location between the projects is changed and also the relative locations in the solutions. 项目之间的相对位置以及解决方案中的相对位置也会发生变化。

The question is how to make change in the best manner: - How to Fix all the references of each project? 问题是如何以最佳方式进行更改: - 如何修复每个项目的所有参考? - How to fix all the solutions? - 如何解决所有解决方案? - Is there any tool available for that? - 有没有可用的工具?

If using option 2: 如果使用选项2:

Move your non csproj/sln files to their target locations, make sure you understand the relative changes in your paths. 将非csproj / sln文件移动到其目标位置,确保您了解路径中的相对更改。

A couple of additions: 几个补充:

  1. I'd have the script perform the required file operations as well. 我也让脚本执行所需的文件操作。 Of course, make sure to back up your original solution first. 当然,请务必先备份原始解决方案。
  2. .sln files are not XML. .sln文件不是 XML。 They are text files with a pretty straightforward syntax, though. 但它们是具有非常简单的语法的文本文件。 So, either you'll have to write your own parser, or consider using Visual Studio's DTE automation object to manipulate the contents of the solution file as shown in this thread: Easy way to add multiple existing .csproj to a Visual Studio Solution? 因此,要么您必须编写自己的解析器,要么考虑使用Visual Studio的DTE自动化对象来操作解决方案文件的内容,如此线程所示: 将多个现有.csproj添加到Visual Studio解决方案的简单方法? . The sample is written in PowerShell but the approach would be the same in, say, VBScript. 该示例是用PowerShell编写的,但这种方法在VBScript中是相同的。

I am not aware of any tools that exist to automatically do this, but I do know of two options that you have, option 1 is to use VS to do the refactor (longer) or option 2 is to use something like powershell (or your favorite scripting language) to update the sln and csproj references. 我不知道有任何工具可以自动执行此操作,但我知道您有两个选项,选项1是使用VS来执行重构(更长)或选项2是使用类似PowerShell(或者您的最喜欢的脚本语言)来更新sln和csproj引用。

If you are using option 1: 如果您使用选项1:

  1. Create your new directories using VS, and manually move the files into them 使用VS创建新目录,然后手动将文件移入其中
  2. Move your SLN files around by hand (the references inside the files are all relative) the sub folder references will remain intact. 手动移动SLN文件(文件内的引用都是相对的)子文件夹引用将保持不变。

If using option 2: 如果使用选项2:

  1. Move your non csproj/sln files to their target locations, make sure you understand the relative changes in your paths. 将非csproj / sln文件移动到其目标位置,确保您了解路径中的相对更改。
  2. Create a script which can handle XML files (for the proj files, you will need regular text parsing for the SLN files), and open the files. 创建一个可以处理XML文件的脚本(对于proj文件,您需要对SLN文件进行常规文本解析),然后打开文件。 Retarget each "item" node with a path in it (will either be ..\\, , or file.etx) to the recalculated target location. 将每个“item”节点重新定位到其中的路径(将是.. \\ ,,或file.etx)到重新计算的目标位置。

Unfortunately it will be pretty manual, and pretty error prone. 不幸的是,它将非常手动,并且非常容易出错。 I recommend option #1, and have just gotten done doing it on a project with 100+ csproj and 30 sln files. 我推荐选项#1,并且刚刚完成了一个包含100多个csproj和30个sln文件的项目。 There were about 4000 source files, which I moved by hand and then used find replace in vs studio (with the project unloaded) to update. 大约有4000个源文件,我手动移动然后在vs studio中使用find replace(项目已卸载)进行更新。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM