2014-09-20 186 views
1

我遇到问题了解如何在安装我的NuGet软件包时转换web.config文件。它正在做一些转变,但不是全部。Nuget web.config.install.xdt不能转换

这里有我需要安装我的NuGet包后修改不变的web.config文件:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    </appSettings> 
    <system.web> 
    <authentication mode="None" /> ***** I want this removed ***** 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 
    <system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" /> ***** I want this removed ***** 
    </modules> 
    </system.webServer> 
</configuration> 

这就是我想要的结果:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    <add key="MvcMailer.BaseURL" value="" /> 
    <add key="SecurityGuardEmailFrom" value="[email protected]" /> 
    <add key="SecurityGuardEmailSubject" value="Your Password has been reset." /> 
    <add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" /> 
    </appSettings> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/SGAccount/Login" timeout="2880" /> 
    </authentication> 
    </system.web> 
    <system.webServer> 
    <modules> 
    </modules> 
    </system.webServer> 
</configuration> 

这种转化的网页。配置文件在MVC应用程序,这是不正确的:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <appSettings> 
    <add key="webpages:Version" value="3.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    <add key="MvcMailer.BaseURL" value="" /> 
    <add key="SecurityGuardEmailFrom" value="[email protected]" /> 
    <add key="SecurityGuardEmailSubject" value="Your Password has been reset." /> 
    <add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" /> 
    </appSettings> 
    <system.web> 
    <authentication mode="None" /> ***** Not removed when it should be ***** 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/SGAccount/Login" timeout="2880" /> 
    </authentication> 
    </system.web> 
    <system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" /> ***** Not removed when it should be ***** 
    </modules> 
    </system.webServer> 
</configuration> 

这是我的我们b.config.install.xdt文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <system.web> 
    <authentication mode="None" xdt:Transform="Remove" xdt:Locator="Match(mode)" /> 
    <authentication mode="Forms" xdt:Transform="Insert"> 
     <forms loginUrl="~/SGAccount/Login" timeout="2880" /> 
    </authentication> 
    </system.web> 
    <system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" xdt:Transform="Remove" xdt:Locator="Match(name)" /> 
    </modules> 
    </system.webServer> 
</configuration> 

我读过的Nuget.org网站关于如何使用XDT转换所有文件,它甚至还可以在这个网站测试仪; https://webconfigtransformationtester.apphb.com/,但它不起作用。

我很难过。有关如何完成这项工作的任何建议?

+1

您写的转换似乎不能在webconfigtransformationtester站点中工作。它失败了,因为第一个定位器试图匹配不存在的name属性。第一个定位器匹配应该是'xdt:Locator =“Match(mode)”' – 2014-09-20 19:03:58

+0

@MattWard - 你是对的,我在这个例子中犯了一个错误。否则它应该在测试器中工作,但在安装Nuget包时它仍然不起作用。 – 2014-09-20 20:53:22

+0

在Visual Studio中使用NuGet 2.8.1对你来说,你的转换看起来很好。 – 2014-09-21 10:19:41

回答

1

这里的新web.config.install.xdt的样子是处理成功的工作:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <appSettings> 
    <add key="SecurityGuardEmailFrom" value="[email protected]" xdt:Transform="Insert" /> 
    <add key="SecurityGuardEmailSubject" value="Your Password has been reset." xdt:Transform="Insert" /> 
    <add key="SecurityGuardEmailTemplatePath" value="~/MailerTemplates/ResetPassword.html" xdt:Transform="Insert" /> 
    </appSettings> 
    <system.web> 
    <authentication mode="Forms" xdt:Transform="SetAttributes" /> 
    <authentication mode="Forms"> 
     <forms loginUrl="~/SGAccount/Login" timeout="2880" xdt:Transform="Insert" /> 
    </authentication> 
    </system.web> 
    <system.webServer> 
    <modules> 
     <remove name="FormsAuthentication" xdt:Transform="Remove" /> 
    </modules> 
    </system.webServer> 
</configuration> 

而不是试图删除原来的认证元素,我改变了模式属性,然后我插入表单元素。其他人似乎一旦工作正常就自行解决。

相关问题