如何将xml文件添加到网站的App_Data文件夹中,然后使用NuGet对其进行修改

问题描述:

我正在创建一个NuGet包,用于添加或修改多个xml文件。我想让Nuget包添加并修改xml文件,这样用户不必做任何事情就可以添加文件,如果它不存在。我需要修改xml文件以针对特定应用程序进行自定义。如何将xml文件添加到网站的App_Data文件夹中,然后使用NuGet对其进行修改

我使用的.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文件。

我正在使用自定义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知道足以卸载依赖包,此类更改可能涉及多个依赖关系。

任何人都知道如何去做到这一点?

+0

我在这找到了自己的问题的答案。以下行删除了依赖关系:uninstall-package library -removedependencies –