久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

“復制本地"的最佳做法是什么?和項目參考

What is the best practice for quot;Copy Localquot; and with project references?(“復制本地的最佳做法是什么?和項目參考?)
本文介紹了“復制本地"的最佳做法是什么?和項目參考?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個大型 c# 解決方案文件(約 100 個項目),我正在努力縮短構建時間.我認為復制本地"在很多情況下對我們來說是一種浪費,但我想知道最佳實踐.

I have a large c# solution file (~100 projects), and I am trying to improve build times. I think that "Copy Local" is wasteful in many cases for us, but I am wondering about best practices.

在我們的 .sln 中,應用程序 A 依賴于程序集 B,而程序集 B 又依賴于程序集 C.在我們的例子中,有幾十個B"和少數C".由于這些都包含在 .sln 中,因此我們使用的是項目引用.當前所有程序集都構建到 $(SolutionDir)/Debug(或 Release)中.

In our .sln, we have application A depending on assembly B which depends on assembly C. In our case, there are dozens of "B" and a handful of "C". Since these are all included in the .sln, we're using project references. All assemblies currently build into $(SolutionDir)/Debug (or Release).

默認情況下,Visual Studio 將這些項目引用標記為復制本地",這會導致每個C"被復制到 $(SolutionDir)/Debug 中,對于每個構建的B".這似乎很浪費.如果我只關閉復制本地"會出現什么問題?其他擁有大型系統的人是做什么的?

By default, Visual Studio marks these project references as "Copy Local", which results in every "C" being copied into $(SolutionDir)/Debug once for every "B" that builds. This seems wasteful. What can go wrong if I just turn "Copy Local" off? What do other people with large systems do?

跟進:

很多回復建議將構建分解為更小的 .sln 文件...在上面的示例中,我將首先構建基礎類C",然后是大部分模塊B",然后是一些應用程序,A".在這個模型中,我需要從 B 獲得對 C 的非項目引用.我遇到的問題是調試"或發布"被納入提示路徑,我最終構建了B"的發布版本針對C"的調試版本.

Lots of responses suggest breaking up the build into smaller .sln files... In the example above, I would build the foundation classes "C" first, followed by the bulk of the modules "B", and then a few applications, "A". In this model, I need to have non-project references to C from B. The problem I run into there is that "Debug" or "Release" gets baked into the hint path and I wind up building my Release builds of "B" against debug builds of "C".

對于那些將構建拆分為多個 .sln 文件的人,您如何處理這個問題?

For those of you that split the build up into multiple .sln files, how do you manage this problem?

推薦答案

在之前的項目中,我使用了一個帶有項目引用的大型解決方案,但也遇到了性能問題.解決方案是三倍:

In a previous project I worked with one big solution with project references and bumped into a performance problem as well. The solution was three fold:

  1. 始終將 Copy Local 屬性設置為 false 并通過自定義 msbuild 步驟強制執行此操作

  1. Always set the Copy Local property to false and enforce this via a custom msbuild step

將每個項目的輸出目錄設置為同一個目錄(最好相對于$(SolutionDir)

Set the output directory for each project to the same directory (preferably relative to $(SolutionDir)

框架附帶的默認 cs 目標計算要復制到當前正在構建的項目的輸出目錄的引用集.由于這需要在參考"關系下計算傳遞閉包,這可能會變得非常代價高昂.我的解決方法是在導入 Microsoft 后在每個項目中導入的通用目標文件(例如 Common.targets )中重新定義 GetCopyToOutputDirectoryItems 目標.CSharp.targets.導致每個項目文件如下所示:

The default cs targets that get shipped with the framework calculate the set of references to be copied to the output directory of the project currently being built. Since this requires calculating a transitive closure under the 'References' relation this can become VERY costly. My workaround for this was to redefine the GetCopyToOutputDirectoryItems target in a common targets file (eg. Common.targets ) that's imported in every project after the import of the Microsoft.CSharp.targets. Resulting in every project file to look like the following:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ... snip ...
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)Microsoft.CSharp.targets" />
  <Import Project="[relative path to Common.targets]" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

這將我們在給定時間的構建時間從幾個小時(主要是由于內存限制)減少到了幾分鐘.

This reduced our build time at a given time from a couple of hours (mostly due to memory constraints), to a couple of minutes.

可以通過從 C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft 復制第 2,438–2,450 和 2,474–2,524 行來創建重新定義的 GetCopyToOutputDirectoryItems.Common.targets 變成 Common.targets.

The redefined GetCopyToOutputDirectoryItems can be created by copying the lines 2,438–2,450 and 2,474–2,524 from C:WINDOWSMicrosoft.NETFrameworkv2.0.50727Microsoft.Common.targets into Common.targets.

為了完整起見,生成的目標定義變為:

For completeness the resulting target definition then becomes:

<!-- This is a modified version of the Microsoft.Common.targets
     version of this target it does not include transitively
     referenced projects. Since this leads to enormous memory
     consumption and is not needed since we use the single
     output directory strategy.
============================================================
                    GetCopyToOutputDirectoryItems

Get all project items that may need to be transferred to the
output directory.
============================================================ -->
<Target
    Name="GetCopyToOutputDirectoryItems"
    Outputs="@(AllItemsFullPathWithTargetPath)"
    DependsOnTargets="AssignTargetPaths;_SplitProjectReferencesByFileExistence">

    <!-- Get items from this project last so that they will be copied last. -->
    <CreateItem
        Include="@(ContentWithTargetPath->'%(FullPath)')"
        Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='Always' or '%(ContentWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"
            >
        <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectoryAlways"
                Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectory"
                Condition="'%(ContentWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
    </CreateItem>

    <CreateItem
        Include="@(_EmbeddedResourceWithTargetPath->'%(FullPath)')"
        Condition="'%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='Always' or '%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"
            >
        <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectoryAlways"
                Condition="'%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectory"
                Condition="'%(_EmbeddedResourceWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
    </CreateItem>

    <CreateItem
        Include="@(Compile->'%(FullPath)')"
        Condition="'%(Compile.CopyToOutputDirectory)'=='Always' or '%(Compile.CopyToOutputDirectory)'=='PreserveNewest'">
        <Output TaskParameter="Include" ItemName="_CompileItemsToCopy"/>
    </CreateItem>
    <AssignTargetPath Files="@(_CompileItemsToCopy)" RootFolder="$(MSBuildProjectDirectory)">
        <Output TaskParameter="AssignedFiles" ItemName="_CompileItemsToCopyWithTargetPath" />
    </AssignTargetPath>
    <CreateItem Include="@(_CompileItemsToCopyWithTargetPath)">
        <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectoryAlways"
                Condition="'%(_CompileItemsToCopyWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectory"
                Condition="'%(_CompileItemsToCopyWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
    </CreateItem>

    <CreateItem
        Include="@(_NoneWithTargetPath->'%(FullPath)')"
        Condition="'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='Always' or '%(_NoneWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"
            >
        <Output TaskParameter="Include" ItemName="AllItemsFullPathWithTargetPath"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectoryAlways"
                Condition="'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='Always'"/>
        <Output TaskParameter="Include" ItemName="_SourceItemsToCopyToOutputDirectory"
                Condition="'%(_NoneWithTargetPath.CopyToOutputDirectory)'=='PreserveNewest'"/>
    </CreateItem>
</Target>

有了這個解決方法,我發現在一個解決方案中擁有多達 120 個項目是可行的,這主要的好處是項目的構建順序仍然可以由 VS 確定,而不是通過拆分手動完成提出你的解決方案.

With this workaround in place I found it workable to have as much as > 120 projects in one solution, this has the main benefit that the build order of the projects can still be determined by VS instead of doing that by hand by splitting up your solution.

這篇關于“復制本地"的最佳做法是什么?和項目參考?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Is there a way to know if someone has bookmarked your website?(有沒有辦法知道是否有人為您的網站添加了書簽?)
Use of Different .Net Languages?(使用不同的 .Net 語言?)
Is there a C# library that will perform the Excel NORMINV function?(是否有執行 Excel NORMINV 函數的 C# 庫?)
Determining an #39;active#39; user count of an ASP.NET site(確定 ASP.NET 站點的“活動用戶數)
Select x random elements from a weighted list in C# (without replacement)(從 C# 中的加權列表中選擇 x 個隨機元素(無需替換))
Best way to keep track of current online users(跟蹤當前在線用戶的最佳方式)
主站蜘蛛池模板: 欧美精品a∨在线观看不卡 欧美日韩中文字幕在线播放 | 一区二区三区精品视频 | 国产日韩欧美一区二区 | 免费能直接在线观看黄的视频 | 国产精品一区二区三区在线播放 | 精品一区二区久久久久久久网精 | 狠狠操狠狠 | 精品国产乱码久久久久久丨区2区 | 黄网站在线播放 | 永久av| 天堂资源 | 色婷婷综合久久久中字幕精品久久 | 日韩国产精品一区二区三区 | 久草影视在线 | 欧洲精品在线观看 | 成人在线欧美 | 成人av鲁丝片一区二区小说 | 国产成人叼嘿视频在线观看 | 成人精品一区二区三区中文字幕 | 日韩成人免费视频 | 皇色视频在线 | 免费一级大片 | 人人射人人插 | 一级黄色片网址 | 欧美一级大片 | 日本高清不卡视频 | 国产高清久久 | 久久久不卡网国产精品一区 | 天天看天天摸天天操 | 午夜精品导航 | 成人做爰www免费看视频网站 | 久久精品综合 | 欧美成年网站 | 91成人在线 | 久久久久久久久蜜桃 | 99看片网| 中文字幕日韩欧美一区二区三区 | 一区二区三区国产精品 | 在线观看成年人视频 | 在线免费看黄 | 91av国产在线视频 |