如何为引用的 nuget 包指定输出文件夹?

How to specify output folder for the referenced nuget packages?(如何为引用的 nuget 包指定输出文件夹?)
本文介绍了如何为引用的 nuget 包指定输出文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,其中引用了一些 nuget 包.

I have a project with some nuget packages referenced.

在输出文件夹(binDebugbinRelease)中,所有引用的库都位于可执行文件旁边.

In output folders (binDebug or binRelease), all referenced libraries lie next to the executable.

如何指定库的输出文件夹?
我想要 binReleaseLibs 中的所有 nuget 库和 binRelease 中的可执行文件.

How to specify output folder for libraries?
I want all nuget libraries in binReleaseLibs and executable in binRelease.

推荐答案

感谢 zivkan 的 调查我找到了答案.传统项目的目标 CopyFilesToOutputDirectory 取决于 _CopyFilesMarkedCopyLocal 目标.在最后一个我们有任务 Copy:

Grace to the zivkan's investigation I found the answer. Traditional project has target CopyFilesToOutputDirectory which depends on _CopyFilesMarkedCopyLocal target. In this last one we have task Copy:

<Copy
    SourceFiles="@(ReferenceCopyLocalPaths)"
    DestinationFiles="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"
    SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
    OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
    Retries="$(CopyRetryCount)"
    RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
    UseHardlinksIfPossible="$(CreateHardLinksForCopyLocalIfPossible)"
    UseSymboliclinksIfPossible="$(CreateSymbolicLinksForCopyLocalIfPossible)"
    Condition="'$(UseCommonOutputDirectory)' != 'true'"
        >

在这里我找到了元数据 DestinationSubDirectory,这正是我需要更改的.

And here I found metadata DestinationSubDirectory which is exactly what I need to change.

首先,我们需要更改csproj文件并添加以下几行:

First, we need to change csproj file and add these lines:

  <ItemDefinitionGroup>
    <ReferenceCopyLocalPaths>
      <DestinationSubDirectory>lib</DestinationSubDirectory>
    </ReferenceCopyLocalPaths>
  </ItemDefinitionGroup>

第二,我们需要修改app.config文件让程序集知道库的路径:

Second, we need to change app.config file to let the assembly know the path to the libraries:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="lib;libs" />
    </assemblyBinding>
  </runtime>

就是这样.所有引用的库将被复制到子文件夹 lib

That's all. All referenced libraries will be copied into subfolder lib

这篇关于如何为引用的 nuget 包指定输出文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)