如何将文件从 .NET Core csproj 中引用的 NuGet 包复制到输出目录? [英] How to copy files to output directory from a referenced NuGet package in .NET Core csproj?

查看:60
本文介绍了如何将文件从 .NET Core csproj 中引用的 NuGet 包复制到输出目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 .NET 核心 csproj 应用程序中使用 PhantomJS NuGet 包.但我认为对 NuGet 使用新的 PackageReference 语法是不可能的.

I'm trying to use PhantomJS NuGet package in .NET core csproj application. But I think it is not possible using new PackageReference syntax for NuGet.

当我像这样引用 PhantomJS 包时:

When I reference the PhantomJS package like this:

<PackageReference Include="PhantomJS" Version="2.1.1">
  <IncludeAssets>all</IncludeAssets>
</PackageReference>

当我运行 dotnet build 时它不会做任何事情.

It does not do anything when I run dotnet build.

我希望它将 PhantomJS 包内的文件复制到输出目录(或项目中的任何位置),以便我可以使用 PhantomJS 包提供的二进制文件.

I'd expect it to copy the files inside PhantomJS package to the output directory (or anywhere in the project) so I could use the binary file provided by the PhantomJS package.

还有其他方法可以用 MSBuild 将 PhantomJS NuGet 包的内容复制到输出目录吗?

Is there another way to copy the contents of PhantomJS NuGet package to the output directory with MSBuild?

推荐答案

我想你想使用:

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

在主 中,这会导致将所有依赖项复制到输出文件夹.这意味着每个依赖项都会被复制,因此在某些情况下这可能会很混乱.

in the main <PropertyGroup>, which causes all dependencies to be copied to the output folder. This means every single dependency gets copied though so this can be quite a mess in some situations.

如果您想排除特定的程序集或包:

If you then want to exclude specific assemblies or packages:

<ItemGroup>
    <-- won't copy to output folder -->
    <PackageReference Include="MahApps.Metro" version="1.6.5">
      <IncludeAssets>compile</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Dragablz" version="0.0.3.203">
      <IncludeAssets>compile</IncludeAssets>
    </PackageReference>
    ... 

    <-- normal will copy to output folder -->
    <PackageReference Include="xmlrpcnet" version="3.0.0.266" />
    <PackageReference Include="YamlDotNet" version="6.0.0" />
</ItemGroup>


<ItemGroup>
    <!-- keep assembly reference from copying to output -->
    <Reference Include="$(SolutionDir)MarkdownMonsterin$(Configuration)$(TargetFramework)MarkdownMonster.exe">
      <Private>false</Private>
    </Reference> 
</ItemGroup>

compile 在此上下文中表示它们可用于编译,但不会复制到输出文件夹.

compile in this context means they are available for compilation, but aren't copied to the output folder.

这篇关于如何将文件从 .NET Core csproj 中引用的 NuGet 包复制到输出目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆