VS2017 nuget 包文件被视为链接而不是实际文件 [英] VS2017 nuget package files treated as link instead of actual file

查看:34
本文介绍了VS2017 nuget 包文件被视为链接而不是实际文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 csproj 文件创建 nuget.我的文件被复制,但当 nuget 包被另一个项目导入时,我的 log4net.config(和其他文件)被视为链接.这些文件也不会在构建时复制到目标目录.(见下方屏幕截图中的蓝色图标)

I am trying to create a nuget using the csproj file. My files are copied, but my log4net.config (and others) are treated as a link when the nuget package is imported by another project. These files are also not copied to the target directory on build. (see the blue icon in the screenshot below)

我的 cs 项目包含以下代码.

My cs project contains the following code.

<ItemGroup>
  <Content Include="contentFiles/**/*.*;log4net.config" copyToOutput="true">
    <IncludeInPackage>true</IncludeInPackage>
    <CopyToOutput>true</CopyToOutput>
    <BuildAction>Content</BuildAction>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>

我需要做什么才能使 log4net.config:

What do I need to do so that the log4net.config:

1 - 不被视为链接文件

1 - is not treated as a linked file

2 - 默认复制到 outbut 目录.

2 - is copied to outbut directory by default.

推荐答案

我需要做什么才能使 log4net.config: 1 - 不被视为链接文件

What do I need to do so that the log4net.config: 1 - is not treated as a linked file

这是设计使然.contentFiles 应该作为链接添加.不支持将文件复制到项目的源目录中,并且一直是经典项目不鼓励的做法.

This is by design. contentFiles are supposed to be added as a link. Copying files into the project's source directory is not supported and has been a discouraged practice for classic projects.

此处查看 Martin 的回答:

Check Martin`s answer here:

这是设计使然.NuGet 包不再应该修改项目的源代码,而只能添加到其构建的输出或构建过程中(除了 .NET 库). 用于向项目添加源代码的内容文件夹仅继续支持基于 packages.config 的项目,因为这对现有项目来说是一个重大更改,但使用 project.json 或 PackageReference (VS 2017) 的项目会获得新行为.

This is by design. NuGet packages are no longer supposed to modify the project's source but only add to its built output or build process (in addition to .NET libraries). The content folder for adding sources to the project is only continued to be supported for packages.config based projects since it would be a breaking change for existing projects, but projects using project.json or PackageReference (VS 2017) get the new behaviour.

现在,contentFiles 部分将为这些文件生成的 msbuild 项控制在 obj\projectname.csproj.nuget.g.props 文件中.

Now, The contentFiles section controls the msbuild items that are generated for these files into the obj\projectname.csproj.nuget.g.props file.

2 - 默认复制到 outbut 目录.

2 - is copied to outbut directory by default.

您可以在 .nuspec 文件中为 log4net.config 设置 copyToOutput="true":

You can set copyToOutput="true" for the log4net.config in the .nuspec file:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <id>xxxx</id>
    <version>1.0.0</version>
    <authors>Tester</authors>
    <owners>Tester</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <contentFiles>
      <files include="any/any/Views/log4net.config" buildAction="content" flatten="true" copyToOutput="true"/>
  </metadata>

    <files>
      <file src="contentFiles/any/any/log4net.config" target="contentFiles/any/any/log4net.config" />
    </files>

您可以查看文档 NuGet ContentFiles Demystified此线程了解更多详情.

You can check the document NuGet ContentFiles Demystified and this thread for more details.

这篇关于VS2017 nuget 包文件被视为链接而不是实际文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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