Nuget package 如何将xml文件添加到网站的App_数据文件夹,然后使用NuGet对其进行修改

Nuget package 如何将xml文件添加到网站的App_数据文件夹,然后使用NuGet对其进行修改,nuget-package,nuget-spec,Nuget Package,Nuget Spec,我正在创建一个NuGet包,用于添加或修改几个xml文件。我希望Nuget包添加并修改xml文件,这样,如果文件不存在,用户就不必做任何事情来添加文件。我需要修改xml文件以针对特定应用程序进行自定义 我在.nuspec文件中使用的代码是: <files> <file src="web.config.*.xdt" target="content"/> <file src="App_Data\*.xml" target="content\App_Dat

我正在创建一个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>

如果文件不存在,则代码将添加该文件;如果文件存在,则代码将对其进行修改,但不会添加文件,然后对其进行修改

我尝试添加的每个文件都将修改为与之关联的.install.xml.xdt文件

我正在使用自定义角色管理器。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>

$id$
$version$
$title$
蒂莫西·R·杜林
$author$
假的
$description$
此版本包中所做更改的摘要。
版权所有2017
这种方法唯一的麻烦是您必须卸载依赖项或手动删除添加的文件,以便完全撤消对应用程序所做的更改

如果主包中的nuspec知道足够多的信息来卸载依赖包,那么这样的更改可能会涉及多个依赖项,这将是更好的选择


有人知道如何让它做到这一点吗?

我找到了我自己问题的答案。以下行删除依赖项:卸载程序包库-removedependencies