gpt4 book ai didi

visual-studio-2017 - VS2017 nuget 包文件被视为链接而不是实际文件

转载 作者:行者123 更新时间:2023-12-05 04:05:50 24 4
gpt4 key购买 nike

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

log4net as a "project" link

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

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

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

1 - 不被视为链接文件

2 - 默认复制到 outbut 目录。

最佳答案

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

这是设计使然。 contentFiles 应该作为链接添加。不支持将文件复制到项目的源目录中,这对于经典项目来说是不鼓励的做法。

查看 Martin 的回答 here :

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 文件中。

2 - is copied to outbut directory by default.

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

<?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 Demystifiedthis thread了解更多详情。

关于visual-studio-2017 - VS2017 nuget 包文件被视为链接而不是实际文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50677740/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com