对于使用 packages.config 的项目,是否有替代 contentFiles 的方法? [英] Is there an alternative to contentFiles with projects that use packages.config?

查看:18
本文介绍了对于使用 packages.config 的项目,是否有替代 contentFiles 的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 nuget 包,其中包含我希望在用户安装我的包时复制到构建输出的内容.对此有支持:NuGet ContentFiles Demystified 在 NuGet v3.3 中.但是,它只适用于使用 project.json 的项目.当我有一个使用 packages.config 的项目时,不会将 contentFiles 复制到我的构建输出中.

I have a nuget package with content that I want to be copied to the build output when users install my package. There is support for this: NuGet ContentFiles Demystified in NuGet v3.3. However, it only works in projects that use project.json. The contentFiles are not copied to my build output when I have a project that uses packages.config.

是否有替代方案或解决方法可以让我的 NuGet 包在使用 project.jsonpackages.config 的项目上工作?

Is there an alternative or workaround I could use in order to make my NuGet package work on projects that use either a project.json or packages.config?

推荐答案

在 StackOverflow 上快速搜索会发现以下问题,我认为它涵盖了您的要求:

A quick search on StackOverflow reveals the following question which I think covers what you are asking for:

将内容文件设置为复制"本地:总是在 nuget 包中

您可以将文件放在 内容目录 在 NuGet 包中.

You can put your files inside a Content directory inside the NuGet package.

在您的 .nuspec 文件中:

In your .nuspec file:

<file src="cssmobile*.css" target="contentcssmobile" />

当您将它安装到您的项目中时,它会将 cssmobile 目录添加到您的项目以及该目录中的文件.

When you install that into your project it will add the cssmobile directory to your project and the files inside that directory.

但是,这只会将文件添加到项目中.为了将它们复制到您的输出目录,您需要使用 PowerShell 脚本来修改项目项的复制本地信息.

However that only adds the files to the project. In order to get them to be copied to your output directory you would either need to use a PowerShell script to modify the project item's copy local information.

另一种可能更好的方法是使用自定义 MSBuild .targets 文件.这将作为导入添加到您的项目中,然后在您的 .targets 文件中,您可以添加所需的文件并指定副本以直接输出信息,就好像它是您项目的一部分一样.NuGet .nupkg 文件内容:

An alternative, possibly a better way, would be to use a custom MSBuild .targets file. This will be added as an import to your project and then inside your .targets file you can add the files you want and specify the copy to output information directly as though it was part of your project. NuGet .nupkg file content:

uild
    Net45
        MyPackage.targets
        Foo.txt

MyPackage 是上面 NuGet 包的 id.

MyPackage is the id of the NuGet package above.

在 .targets 文件中指定文件(例如 Foo.txt).

Inside the .targets file you specify the files (e.g. Foo.txt).

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <None Include="Foo.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

这篇关于对于使用 packages.config 的项目,是否有替代 contentFiles 的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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