I have a solution with multiple MVC and libraries projects and the build of this solution is very slow.
我有一个包含多个MVC和库项目的解决方案,这个解决方案的构建非常慢。
To improve the build performance, I changed all projects to output in the same folder and changed all project references to copy local = false, this improved the build performance almost in 90%, from 10m to 1m30s.
为了提高构建性能,我将所有项目更改为在同一文件夹中输出,并将所有项目引用更改为copy local = false,这使得构建性能几乎提高了90%,从10m到1m30s。
However, this generated an issue, in run mode my application show errors because have no references assemblies in the output folder.
但是,这会产生一个问题,在运行模式下,我的应用程序显示错误,因为输出文件夹中没有引用程序集。
I'd like to know if exists a way, to make solution copy the references only one time to my output folder.
我想知道是否存在一种方法,使解决方案只将引用复制一次到我的输出文件夹。
I tried somethings, like a target to copy the dlls from packages folder to the output folder, but this not work correctly, because in a packages folder can exists dlls from many framework versions.
我尝试了一些东西,比如将目标从packages文件夹复制到输出文件夹,但这不能正常工作,因为在一个包文件夹中可以存在来自许多框架版本的dll。
Any ideia to solve this issue?
有什么想法来解决这个问题吗?
1 个解决方案
#1
1
One common solution is to have all projects output to the same directory, and have all references set to CopyLocal=False, and then have one extra project (or an existing one, like the main application) targetting the same output directory and which contains all references and has CopyLocal=True. Then that one project effectively takes care of getting all your references where you want them. To get all projects use the same output directory I'd suggest to modify the .csproj files to all import the same file which sets the OutputPath property instead of manually changing it in each project.
一个常见的解决方案是将所有项目输出到同一目录,并将所有引用设置为CopyLocal = False,然后有一个额外的项目(或现有的项目,如主应用程序),目标是相同的输出目录,并包含所有项目引用并具有CopyLocal = True。然后,这个项目有效地将所有引用都放在您想要的位置。为了让所有项目使用相同的输出目录,我建议修改.csproj文件以导入相同的文件,该文件设置OutputPath属性,而不是在每个项目中手动更改它。
Alternatively, since you mention the main problem with a single output directory and CopyLocal set to True is that some files get copied multiple times, you could modify how the copying occurs. Normally, by default, the Copy tasks used will skip files with matching timestamps. This is controlled by the SkipCopyUnchangedFiles flag so you could force it to true and see if that changes anything:
或者,由于您提到单个输出目录的主要问题而且CopyLocal设置为True,因此某些文件会被多次复制,您可以修改复制的方式。通常,默认情况下,使用的复制任务将跳过具有匹配时间戳的文件。这是由SkipCopyUnchangedFiles标志控制的,因此你可以强制它为true,看看是否有任何改变:
msbuild my.sln /p:SkipCopyUnchangedFiles=True
Or you could even ask it to use hardlinks instead of copying, this should effectively mean no copies are made at all:
或者您甚至可以要求它使用硬链接而不是复制,这实际上应该意味着根本不会制作副本:
msbuild my.sln /p:CreateHardLinksForCopyLocalIfPossible=True
or symbolic links:
或符号链接:
msbuild my.sln /p:CreateSymbolicLinksForCopyLocalIfPossible=True
If all else fails and files are still copied more than once it could mean e.g. that one project references A.dll and another one also references A.dll but from a different directory or a different version etc, so it will get copied twice no matter what unless you fix that.
如果所有其他方法都失败并且文件仍然被复制多次,则可能意味着例如一个项目引用A.dll而另一个项目也引用A.dll但是来自不同的目录或不同的版本等,所以除非你修复它,否则它将被复制两次。
#1
1
One common solution is to have all projects output to the same directory, and have all references set to CopyLocal=False, and then have one extra project (or an existing one, like the main application) targetting the same output directory and which contains all references and has CopyLocal=True. Then that one project effectively takes care of getting all your references where you want them. To get all projects use the same output directory I'd suggest to modify the .csproj files to all import the same file which sets the OutputPath property instead of manually changing it in each project.
一个常见的解决方案是将所有项目输出到同一目录,并将所有引用设置为CopyLocal = False,然后有一个额外的项目(或现有的项目,如主应用程序),目标是相同的输出目录,并包含所有项目引用并具有CopyLocal = True。然后,这个项目有效地将所有引用都放在您想要的位置。为了让所有项目使用相同的输出目录,我建议修改.csproj文件以导入相同的文件,该文件设置OutputPath属性,而不是在每个项目中手动更改它。
Alternatively, since you mention the main problem with a single output directory and CopyLocal set to True is that some files get copied multiple times, you could modify how the copying occurs. Normally, by default, the Copy tasks used will skip files with matching timestamps. This is controlled by the SkipCopyUnchangedFiles flag so you could force it to true and see if that changes anything:
或者,由于您提到单个输出目录的主要问题而且CopyLocal设置为True,因此某些文件会被多次复制,您可以修改复制的方式。通常,默认情况下,使用的复制任务将跳过具有匹配时间戳的文件。这是由SkipCopyUnchangedFiles标志控制的,因此你可以强制它为true,看看是否有任何改变:
msbuild my.sln /p:SkipCopyUnchangedFiles=True
Or you could even ask it to use hardlinks instead of copying, this should effectively mean no copies are made at all:
或者您甚至可以要求它使用硬链接而不是复制,这实际上应该意味着根本不会制作副本:
msbuild my.sln /p:CreateHardLinksForCopyLocalIfPossible=True
or symbolic links:
或符号链接:
msbuild my.sln /p:CreateSymbolicLinksForCopyLocalIfPossible=True
If all else fails and files are still copied more than once it could mean e.g. that one project references A.dll and another one also references A.dll but from a different directory or a different version etc, so it will get copied twice no matter what unless you fix that.
如果所有其他方法都失败并且文件仍然被复制多次,则可能意味着例如一个项目引用A.dll而另一个项目也引用A.dll但是来自不同的目录或不同的版本等,所以除非你修复它,否则它将被复制两次。