如何将 xml 文件添加到网站的 App_Data 文件夹,然后使用 NuGet 对其进行修改
How do you add an xml file to the App_Data folder of a web site and then modify it with NuGet
我正在创建一个 NuGet 包来添加或修改几个 xml 文件。我希望 Nuget 包添加然后修改 xml 文件,因此如果文件不存在,用户无需执行任何操作即可添加该文件。我需要修改 xml 文件以针对特定应用对其进行自定义。
我在 .nuspec 文件中使用的代码是:
<files>
<file src="web.config.*.xdt" target="content"/>
<file src="App_Data\*.xml" target="content\App_Data"/>
<file src="App_Data\*.xml.*.xdt" target="content\App_Data"/>
<file src="favicon.ico" target="content\favicon.ico"/>
</files>
with的代码会在文件不存在时添加文件,存在时修改文件,但不会先添加再修改。
我尝试添加的每个文件然后修改为与之关联的 .install.xml.xdt 文件。
我正在使用自定义 RoleManager。 xml 文件内容为:
<?xml version="1.0" encoding="utf-8" ?>
<roleManager />
xml.install 文件包含:
<?xml version="1.0" encoding="utf-8" ?>
<roleManager xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
xdt:Transform = "SetAttributes(defaultProvider,enabled,cacheRolesInCookie,cookieProtection)"
defaultProvider="RoleProvider"
enabled="true"
cacheRolesInCookie="true"
cookieProtection="All" >
<providers xdt:Transform="Insert" >
<clear />
<add name="RoleProvider" type="Library.RoleProvider" applicationName="$RootNamespace$" />
</providers>
</roleManager>
有什么方法可以完成我想做的事情吗?
我有一个初步的解决方法:创建一个依赖解决方案来添加文件。
相关解决方案具有以下 nuspec 部分:
<files>
<file src="App_Data\*.xml" target="content\App_Data"/>
</files>
此 nuget 包随后在主库中列为依赖项:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Timothy R Dooling</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<file src="App_Data\*.xml" target="content\App_Data"/>
<dependencies>
<dependency id="LibraryCore" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="web.config.*.xdt" target="content"/>
<file src="App_Data\*.xml.*.xdt" target="content\App_Data"/>
<file src="favicon.ico" target="content\favicon.ico"/>
</files>
</package>
这种方法的唯一麻烦是您必须卸载依赖项或手动删除添加的文件才能完全撤消对应用程序所做的更改。
如果主包中的 nuspec 知道足以卸载依赖包,则此类更改可能涉及多个依赖项,这将是更好的选择。
有人知道如何让它做到这一点吗?
我正在创建一个 NuGet 包来添加或修改几个 xml 文件。我希望 Nuget 包添加然后修改 xml 文件,因此如果文件不存在,用户无需执行任何操作即可添加该文件。我需要修改 xml 文件以针对特定应用对其进行自定义。
我在 .nuspec 文件中使用的代码是:
<files>
<file src="web.config.*.xdt" target="content"/>
<file src="App_Data\*.xml" target="content\App_Data"/>
<file src="App_Data\*.xml.*.xdt" target="content\App_Data"/>
<file src="favicon.ico" target="content\favicon.ico"/>
</files>
with的代码会在文件不存在时添加文件,存在时修改文件,但不会先添加再修改。
我尝试添加的每个文件然后修改为与之关联的 .install.xml.xdt 文件。
我正在使用自定义 RoleManager。 xml 文件内容为:
<?xml version="1.0" encoding="utf-8" ?>
<roleManager />
xml.install 文件包含:
<?xml version="1.0" encoding="utf-8" ?>
<roleManager xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
xdt:Transform = "SetAttributes(defaultProvider,enabled,cacheRolesInCookie,cookieProtection)"
defaultProvider="RoleProvider"
enabled="true"
cacheRolesInCookie="true"
cookieProtection="All" >
<providers xdt:Transform="Insert" >
<clear />
<add name="RoleProvider" type="Library.RoleProvider" applicationName="$RootNamespace$" />
</providers>
</roleManager>
有什么方法可以完成我想做的事情吗?
我有一个初步的解决方法:创建一个依赖解决方案来添加文件。
相关解决方案具有以下 nuspec 部分:
<files>
<file src="App_Data\*.xml" target="content\App_Data"/>
</files>
此 nuget 包随后在主库中列为依赖项:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<title>$title$</title>
<authors>Timothy R Dooling</authors>
<owners>$author$</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2017</copyright>
<file src="App_Data\*.xml" target="content\App_Data"/>
<dependencies>
<dependency id="LibraryCore" version="1.0.0" />
</dependencies>
</metadata>
<files>
<file src="web.config.*.xdt" target="content"/>
<file src="App_Data\*.xml.*.xdt" target="content\App_Data"/>
<file src="favicon.ico" target="content\favicon.ico"/>
</files>
</package>
这种方法的唯一麻烦是您必须卸载依赖项或手动删除添加的文件才能完全撤消对应用程序所做的更改。
如果主包中的 nuspec 知道足以卸载依赖包,则此类更改可能涉及多个依赖项,这将是更好的选择。
有人知道如何让它做到这一点吗?