来自NuGet包的App.config XML转换 [英] App.config XML transform from NuGet Package
问题描述
我正在尝试遵循 这在运行 在Visual Studio 2017(15.6.4)中,当将NuGet包添加到具有现有原始 任何人都可以建议为什么转换失败吗? 更新 我在目标.NET Framework 4.7.1项目中将PackageReference用作程序包管理格式. 在Visual Studio 2017(15.6.4)中,当将NuGet程序包添加到具有现有原始App.config文件的全新控制台应用程序时,不会进行任何转换. "不进行转换"是什么意思? 我已经用您的 裸包: https://1drv.ms/u/s!Ai1sp_yvodHf1QFNsI3ybdw2nanD /p>
然后将其设置为我的本地提要,创建一个新的.net控制台应用程序并将该nuget包添加到测试项目中,您会发现 所以应该没问题.一种可能是您在安装此软件包时没有清理缓存,要确认这一点,请删除解决方案文件夹下的packages文件夹. 注意: 请注意,NuGet不会替换 更新: 当执行与您完全相同的步骤时,这对我不起作用,但是我使用PackageReference而不是packages.config.这是PackageReference的错误吗? 不是,这不是 对于使用packages.config的项目,NuGet支持在软件包安装和卸载时对源代码和配置文件进行转换的功能.使用PackageReference在项目中安装软件包时,仅应用源代码转换. 我们可能知道packages.config支持对源代码和配置文件进行转换的功能,但是,仅将源代码转换应用于 I am attempting to follow these instructions to perform a simple XML transform on a target App.config file via a custom NuGet package. The The This correctly inserts the file into the In Visual Studio 2017 (15.6.4) when adding the NuGet package to a brand new Console Application with an existing vanilla Can anybody advise why the transformation fails to take place? UPDATE I am using PackageReference as my package management format in the target .NET Framework 4.7.1 project. In Visual Studio 2017 (15.6.4) when adding the NuGet package to a brand new Console Application with an existing vanilla App.config file, no transforms take place. What do you mean "no transforms take place"? The new elements and attributes under the I have created the nuget package with your nuget package: https://1drv.ms/u/s!Ai1sp_yvodHf1QFNsI3ybdw2nanD Then set it to my local feed, create a new .net console application and add that nuget package to the test project, you will find the new elements and attributes under the So it should be works fine. One possibility is you have not clean the cache when you install this package, to confirm this, please delete the packages folder under the solution folder. Note: Notice that NuGet didn't replace the Update: This does not work for me when performing exactly the same steps as you, but I am using PackageReference instead of packages.config. Is this a bug with PackageReference? Not, it is not a bug with For projects using packages.config, NuGet supports the ability to make transformations to source code and configuration files at package install and uninstall times. Only Source code transformations are applied when a package is installed in a project using PackageReference. We could to know packages.config support the ability to make transformations to source code and configuration files, However, Only Source code transformations are applied to the 这篇关于来自NuGet包的App.config XML转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!.nuspec
文件包含以下内容:<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Foo.Bar</id>
<version>1.0.0</version>
<title>Foo Bar</title>
<authors>Foo</authors>
<description>Bar</description>
</metadata>
<files>
<file src="app.config.transform" target="content" />
</files>
</package>
nuget pack
时将文件正确地插入.nupkg
文件中的content
文件夹中.App.config
文件的全新控制台应用程序时,不会进行任何转换(即App.config
的内容不变). XDT转换也是如此.
appSetttings
部分下的新元素和属性未合并到App.config
?.nuspec
和app.config.transform
文件创建了nuget包:appSetttings
部分下的新元素和属性被合并到App.config
中,因此App.config
在安装该nuget软件包后将如下所示:<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<appSetttings>
<add key="foo" value="bar" />
</appSetttings>
</configuration>
startup
部分,它只是通过添加新元素和属性将新条目合并到其中. NuGet不会更改任何现有元素或属性.
PackageReference
的错误.根据文档转换源代码和配置文件,前两行:
PackageReference
.这就是为什么您无法使用PackageReference
进行此工作的原因.app.config.transform
file contains the following content:<configuration>
<appSetttings>
<add key="foo" value="bar" />
</appSetttings>
</configuration>
.nuspec
file contains the following content:<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Foo.Bar</id>
<version>1.0.0</version>
<title>Foo Bar</title>
<authors>Foo</authors>
<description>Bar</description>
</metadata>
<files>
<file src="app.config.transform" target="content" />
</files>
</package>
content
folder in the .nupkg
file when running nuget pack
.App.config
file, no transforms take place (i.e. the content of App.config
is unchanged). This is also the case with XDT transforms.
appSetttings
section not merged into the App.config
?.nuspec
and app.config.transform
files: appSetttings
section are merged into the App.config
, so the App.config
would be like this after install that nuget package:<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1" />
</startup>
<appSetttings>
<add key="foo" value="bar" />
</appSetttings>
</configuration>
startup
section, it just merged the new entry into it by adding only new elements and attributes. NuGet will not change any existing elements or attributes.
PackageReference
. According to doc Transforming source code and configuration files, the top two lines:
PackageReference
. That is reason why you could not get that work with PackageReference
.