.net - NuGet - 如何在消费应用程序构建输出中包含应用程序 app.config 文件?
问题描述
如何让我的 NuGet 包将其 app.config 包含在使用 NuGet 包的项目的构建输出目录中?目前它只是复制 NuGetConfigInclude.exe 但我需要它也有 NuGetConfigInclude.exe.config 文件。请注意,消费应用程序使用 .csproj 文件中的 PackageReference。它不使用 packages.config。
NuGetConfigInclude.nuspec:
<?xml version="1.0"?>
<package >
<metadata>
<id>NuGetConfigInclude</id>
<version>1.0.0.0</version>
<title>NuGetConfigInclude</title>
<authors>NuGetConfigInclude</authors>
<owners>NuGetConfigInclude</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NuGetConfigInclude</description>
<releaseNotes>Test Summary</releaseNotes>
<copyright>Copyright 2020</copyright>
<tags>TEST</tags>
</metadata>
</package>
使用应用程序项目文件:
<ItemGroup>
<PackageReference Include="NuGetConfigInclude">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
更新:
我已经设法让 nuspec 将文件包含在包中,但是在使用项目中它正在尝试编译配置文件:
<?xml version="1.0"?>
<package >
<metadata>
<id>NuGetConfigInclude</id>
<version>24.0.0.0</version>
<title>NuGetConfigInclude</title>
<authors>NuGetConfigInclude</authors>
<owners>NuGetConfigInclude</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NuGetConfigInclude</description>
<releaseNotes>Test Summary</releaseNotes>
<copyright>Copyright 2020</copyright>
<contentFiles>
<files include="contentFiles\any\any\assets\**" buildAction="None" copyToOutput="true" flatten="false" />
</contentFiles>
<tags>TEST</tags>
</metadata>
<files>
<file src="bin\Debug\NuGetConfigInclude.exe.config" target="contentFiles\any\any\assets"/>
</files>
</package>
构建消费项目时的示例错误:
严重性代码描述项目文件行抑制状态错误 CS1022 类型或命名空间定义,或预期的文件结尾 NuGetConsumer C:\Users\GuestAcct.nuget\packages\nugetconfiginclude\24.0.0\contentFiles\any\any\assets\NuGetConfigInclude。 exe.config 1 活动
解决方案
该解决方案有效:
<?xml version="1.0"?>
<package >
<metadata>
<id>NuGetConfigInclude</id>
<version>29.0.0.0</version>
<title>NuGetConfigInclude</title>
<authors>NuGetConfigInclude</authors>
<owners>NuGetConfigInclude</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>NuGetConfigInclude</description>
<releaseNotes>Test Summary</releaseNotes>
<copyright>Copyright 2020</copyright>
<contentFiles>
<files include="**/*.*" buildAction="None" copyToOutput="true" flatten="true" />
</contentFiles>
<tags>TEST</tags>
</metadata>
<files>
<file src="bin\Debug\NuGetConfigInclude.exe.config" target="contentFiles\any\any\"/>
</files>
</package>
需要注意的是,如果您的使用项目正在使用 PackageReference,则需要将文件复制到名为 contentFiles 的文件夹中。
推荐阅读
- html - 具有相同强度定义的更接近元素的 CSS 样式选择器的优先级
- powershell - 使用“>”调用 .EXE-Tool - 命令内部/作为参数
- oauth - 刷新 Keycloak 离线令牌
- python - urllib3 中的相对导入
- parsing - 如何删除 JavaCC 中的左递归?
- ruby-on-rails - 没有收到 ActionMailer,没有错误
- ios - WKBackgroundRefreshTask 在返回之前被释放
- emacs - 为可变间距面中的 unicode 块范围选择字体
- reactjs - 无法读取 React 中未定义错误的属性“名称”
- angular - 指示正在进行异步验证的类