visual-studio Visual Studio 复制项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/884255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:31:16  来源:igfitidea点击:

Visual Studio Copy Project

visual-studiovisual-studio-2008

提问by sarsnake

I would like to make a copy of my project. I would rather not start doing it from scratch by adding files and references, etc. Please note that I don't mean copy for deployment. Just plain copy.

我想复制我的项目。我宁愿不通过添加文件和引用等从头开始做。请注意,我的意思不是复制以进行部署。只是简单的复制。

Is there a tool in VS to do this? I am using VS 2008

VS 中是否有工具可以执行此操作?我正在使用 VS 2008

回答by Mitchel Sellers

If you want a copy, the fastest way of doing this would be to save the project. Then make a copy of the entire thing on the File System. Go back into Visual Studio and open the copy. From there, I would most likely recommend re-naming the project/solution so that you don't have two of the same name, but that is the fastest way to make a copy.

如果您想要一份副本,最快的方法是保存项目。然后在文件系统上制作整个内容的副本。返回 Visual Studio 并打开副本。从那里开始,我很可能会建议重新命名项目/解决方案,以便您不会有两个同名,但这是制作副本的最快方法。

回答by Shane

Just create a template;

只需创建一个模板

From your project chose: Project - Export Template

从您的项目中选择:项目 - 导出模板

The wizard will let you define

向导会让你定义

  • Template name
  • Template Description
  • Icon
  • Preview image
  • 模板名称
  • 模板说明
  • 图标
  • 预览图

Then?it zips up your project into?'My Exported Templates' directory. You also have the?option to?make?your template available?when you create a new project.

然后?它会将您的项目压缩到“我的导出模板”目录中。创建新项目时,您还可以选择使模板可用。

When you use your template to create a new project, the namespace will be correct for 'your_new_project_name' throughout every file, all references correct, everything perfecto :)

当您使用模板创建新项目时,每个文件中的“your_new_project_name”命名空间都是正确的,所有引用都正确,一切都很完美:)

You can send the .zip file to anybody, and they must copy (not unzip) the .zip file into Templates\ProjectTemplates directory for them to use too.

您可以将 .zip 文件发送给任何人,他们也必须将 .zip 文件复制(而不是解压缩)到 Templates\ProjectTemplates 目录中以供他们使用。

I made an ASP.NET MVC template with folders, layout page, viewmodels etc arranged just how I like them.

我制作了一个 ASP.NET MVC 模板,其中包含我喜欢的文件夹、布局页面、视图模型等。

NOTE:
If you have an empty folder in your project, it WON'T be added to the template, so I just added an empty class appropriate to each folder, and a sample?picture for images folder.

注意:
如果你的项目中有一个空文件夹,它不会被添加到模板中,所以我只是添加了一个适合每个文件夹的空类,以及一个用于图像文件夹的示例图片。

回答by quip

I guess if this is something you do often, there's a little (non-free) utility that promises to do it for you: I haven't used it, so not sure how good it is:

我想如果这是你经常做的事情,那么有一个小(非免费)实用程序可以为你做:我没有用过它,所以不确定它有多好:

http://www.kinook.com/CopyWiz/

http://www.kinook.com/CopyWiz/

There is also this project on CodePlex:

CodePlex 上也有这个项目:

http://clone.codeplex.com/

http://clone.codeplex.com/

I will probably give the codeplex project a try, and if it doesn't work I'll manually rename everything and edit the sln file.

我可能会尝试使用 codeplex 项目,如果它不起作用,我将手动重命名所有内容并编辑 sln 文件。

回答by Vikram K

It is highly NOT ADVISABLEto copy projects at all because the some config files formed internally like .csproj, .vspsccetc. may (and most probably will) point to references which belong to previous solutions' location and other paths/locations in system or TFS. Unless you are an expert at reading these files and fixing references, do not try to copy projects.

完全不建议复制项目,因为内部形成的一些配置文件(如.csproj、.vspscc等)可能(并且很可能会)指向属于先前解决方案位置和系统中其他路径/位置的引用或TFS。除非您是阅读这些文件和修复参考的专家,否则不要尝试复制项目。

You can create a skeletal project of the same type you intend to copy, this creates a proper .csproj, .vspsccfiles. Now you are free to copy the class files,scripts and other content from the previous project as they will not impact. This will ensure a smooth build and version control (should you choose to be interested in that)

您可以创建一个与您要复制的类型相同的骨架项目,这将创建一个正确的.csproj、.vspscc文件。现在您可以自由复制之前项目中的类文件、脚本和其他内容,因为它们不会产生影响。这将确保顺利构建和版本控制(如果您选择对此感兴趣)

Having said all this, let me give you the method to copy project anyhow in a step-wise manner:

说了这么多,让我给你分步复制项目的方法:

  1. Go to the project you want to copy in solution explorer and right-click.
  2. Now select 'Open Folder in File Explorer'(Assuming you have the solution mapped to a local path on your disk).
  3. Select the Projects you want to replicate as whole folders(along with all dependencies,bin .vspscc file, .csproj file)
  4. Paste them in your desired location (it could be your same solution folder or even another solution folder. If it is within the same solution folder, then you would be required to rename it, also the .csproj and other internal files to the new name).
  5. No go back to Visual Studio, Right-Click on Solution > Add > Existing Project...
  6. Browse and select the Project file (.csproj file) now from the location you placed it in and select 'open'
  7. This file now appears in the solution explorer for you to work.
  1. 在解决方案资源管理器中转到要复制的项目,然后右键单击
  2. 现在选择在文件资源管理器中打开文件夹(假设您已将解决方案映射到磁盘上的本地路径)。
  3. 选择要作为整个文件夹复制的项目(以及所有依赖项、bin .vspscc 文件、.csproj 文件)
  4. 将它们粘贴到您想要的位置(它可以是您的同一个解决方案文件夹,甚至是另一个解决方案文件夹。如果它在同一个解决方案文件夹中,那么您需要将其重命名,也将 .csproj 和其他内部文件重命名为新名称)。
  5. 不要回到 Visual Studio,右键单击解决方案>添加>现有项目...
  6. 现在从您放置它的位置浏览并选择项目文件(.csproj 文件),然后选择“打开
  7. 此文件现在出现在解决方案资源管理器中供您工作。

You may now have to resolve a few build errors probably with duplicated/missing references and stuff but otherwise it's as pristine in logic and structure as you expected it to be.

您现在可能需要解决一些可能包含重复/缺失引用和内容的构建错误,但除此之外,它在逻辑和结构上与您预期的一样原始。

回答by Giannis Grivas

I follow these steps and I use the development tool called Resharper,which is awesome by the way:

我按照以下步骤操作,并使用名为Resharper的开发工具,顺便说一下,它很棒:

So,

所以,

  1. Copythe existing project folder to the destination you want
  2. Go to source control and with right click just to the root folder you want and pick "Add items to folder...".Then, a wizard will come up to choose the files to copy (there is no need for some files and the wizard guides you for that reason by default).
  3. Change the nameof the solution file (*.sln)
  4. Change the namesof the sub-projects if exist.
  5. Use Resharperto change the binding namespacesname (I will automatic do the dirty job with safety).The alternative way is to manually change all namespaces with the new name.
  6. The same action with method names.
  7. Check solution's propertiesif you want to change.
  1. 现有项目文件夹复制到您想要的目的地
  2. 转到源代码管理并右键单击您想要的根文件夹并选择“将项目添加到文件夹...”。然后,将出现一个向导来选择要复制的文件(不需要某些文件和默认情况下,向导会因此指导您)。
  3. 更改解决方案文件的名称(*.sln)
  4. 如果存在,请更改子项目的名称
  5. 使用Resharper更改绑定命名空间名称(我会自动安全地完成肮脏的工作)。另一种方法是使用新名称手动更改所有命名空间。
  6. 与方法名称相同的操作。
  7. 如果要更改,请检查解决方案的属性

That's it. You are ready!!!

而已。你准备好了!!!

回答by Alperon

The best way is actually to create a new Project from scratch, then go into the folder with the project files you want to copy over (project, form1, everything except folders). Rename the files (Except for form1 files) for example: I copied Ch4Ex1 files into my Ch4Ex2 project but first renamed the files to Ch4Ex2. Copy and paste those files into the Solution Explorer for the new project in Visual Studio. Then just overwrite the files and you should be good to go!

最好的方法实际上是从头开始创建一个新项目,然后进入您要复制的项目文件所在的文件夹(项目,form1,除文件夹外的所有内容)。重命名文件(form1 文件除外),例如:我将 Ch4Ex1 文件复制到我的 Ch4Ex2 项目中,但首先将文件重命名为 Ch4Ex2。将这些文件复制并粘贴到 Visual Studio 中新项目的解决方案资源管理器中。然后只需覆盖文件,您就可以开始使用了!

Old thread but I hope it helps anyone looking for this answer!

旧线程,但我希望它可以帮助任何寻找此答案的人!

回答by Rainald62

I have a project where the source files are in in a folder below the project folder. When I copied the project folder without the source folder and opened the copied project, the source files are not missing but found at the old location. I closed the project, copied also the source folder, and re-opened the project. Now, the project magically references the copied source files (both the new path showed up on "save as" and a change in a file has been saved in the copied version).

我有一个项目,其中源文件位于项目文件夹下方的文件夹中。当我复制没有源文件夹的项目文件夹并打开复制的项目时,源文件没有丢失,而是在旧位置找到。我关闭了项目,也复制了源文件夹,然后重新打开了项目。现在,该项目神奇地引用了复制的源文件(新路径显示在“另存为”中,并且文件中的更改已保存在复制版本中)。

There is a caveat: If not both old and new project folders are below a used library folder, the above-mentioned magic discards also the absolute reference to the library and expects it under the same relative path.

有一个警告:如果不是新旧项目文件夹都在使用的库文件夹下,上述魔术也会丢弃对库的绝对引用,并期望它在相同的相对路径下。

I tried this with VS Express 2012.

我在 VS Express 2012 上试过这个。

回答by Brian

My solution is a little bit different - the computer that the package resided on died and so I was forced to recreate it on another computer.

我的解决方案有点不同 - 包所在的计算机死了,所以我被迫在另一台计算机上重新创建它。

What I did (in VS 2008) was to open the following files in my directory:

我所做的(在 VS 2008 中)是在我的目录中打开以下文件:

                  - <package name>.djproj
                  - <package name>.dtproj.user
                  - <package name>.dtxs
                  - <package name>.sln
                  - Package.dtsx

When I did this a popup window asked me if the sln file was going to be a new solution and when I clicked 'yes' everything worked perfectly.

当我这样做时,一个弹出窗口询问我 sln 文件是否将成为一个新的解决方案,当我单击“是”时,一切正常。

回答by Ganesh Vellanki

After trying above solutions & creating copy for MVC projects

在尝试上述解决方案并为 MVC 项目创建副本后

For MVC projects please update the port numbers in .csproj file, you can take help of iis applicationhost.config to check the port numbers. Same port numbers will cause assembly loading issue in IIS.

MVC项目请更新.csproj文件中的端口号,可以借助iis applicationhost.config查看端口号。相同的端口号会导致 IIS 中的程序集加载问题。

回答by Chris Catignani

Following Shane's answer above (which works great BTW)…

按照上面Shane的回答(BTW效果很好)......

You might encounter a slew of yellow triangles in the reference list. Most of these can be eliminated by a Build->Clean Solutionand Build->Rebuild Solution.

您可能会在参考列表中遇到大量黄色三角形。其中大部分可以通过 aBuild->Clean Solution和消除Build->Rebuild Solution

I did happen to have some Google API references that were a little more stubborn.

我碰巧有一些 Google API 参考,它们有点固执。

Trying to reinstall the NuGet package of the same version didn't work.
Visual Studio thinks you already have it installed.

尝试重新安装相同版本的 NuGet 包不起作用。
Visual Studio 认为您已经安装了它。

To get around this:
1: Write down the original version.
2: Install the next higher version...then uninstall it.
3: Install the original version from step #1.

要解决这个问题:
1:写下原始版本。
2:安装下一个更高版本...然后卸载它。
3:从步骤#1 安装原始版本。