我正在使用web.config转换文件的概念.我有三个网络配置.一个是分期,生产,部署.我对这三个有不同的连接信息.
Web.Config中:
<connectionStrings>
<add name="MyGallery"
connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DevelopmentStorageDb;Data Source=BALA\SQLEXPRESS" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
Web.Config.Production:
<add
name="MyGallery"
connectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SharePoint_Config;Data Source=BALA\SQLEXPRESS"
xdt:Transform="Replace" xdt:Locator="Match(name)"
/>
Run Code Online (Sandbox Code Playgroud)
现在我构建它正常工作的代码.我创建了包.当我在生产模式下运行代码时,新的连接字符串没有占用.
我该怎么解决这个问题.我是否需要额外的努力才能将其移至某个地方
visual-studio-2010 msdeploy visual-studio web-config-transform
如何使用web.config转换在我的作品中包含域属性web.config?
我的基地有以下内容web.config.
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
我试图在我的使用中使用以下内容web.prod.config,但在发布项目时它不会添加属性.
<authentication mode="Forms" xdt:Transform="Replace">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" domain=".mydomain.com" />
</authentication>
Run Code Online (Sandbox Code Playgroud)
我希望输出如下.
<authentication mode="Forms">
<forms loginUrl="~/Account/Login.aspx" timeout="2880" domain=".mydomain.com"/>
</authentication>
Run Code Online (Sandbox Code Playgroud) 我在Visual Studio 2010中遇到"添加配置转换"选项的问题.我有一个ASP.NET 4.0 Web项目,其中定义了以下4种配置模式:
当我右键单击web.config并选择"Add Config Transforms"时,只会添加以下两个配置转换:
"PreProduction"和"Local"文件未显示.是否有一个我错过的设置会导致这两个文件现在出现?
我一直在使用web.config转换,效果很好。我最近刚刚实现了连接字符串加密,并且不确定如何修改我的Release转换。
之前,我只是使用定位器来替换名称设置。
现在设置已加密,现在没有名称了。
<connectionStrings configProtectionProvider="Pkcs12Provider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes192-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>rsaKey</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>CipherValueHere</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>CipherValueHere</CipherValue>
</CipherData>
</EncryptedData>
Run Code Online (Sandbox Code Playgroud)
如何更新我的转换,以替换整个连接字符串部分?元素名称“ connectionStrings”是否有定位符?
非常感谢,约翰
我正在使用以下(大大简化)的MSBuild脚本:
<?xml version="1.0"?>
<Project DefaultTargets="Transform" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="Transform">
<TransformXml Source="../web.config"
Transform="Config\Production\webapp.xml"
Destination="Config\Build\Production\web.config" />
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
这非常适合转换单个配置文件,而无需通过MSDeploy.
但是,让我说在我的变换中我拼错了一个变量.我会收到一个警告:
C:\ MyApp\DevOps\Config\Production\webapp.xml(15,6):警告:源文档中的任何元素都不匹配'/ configuration/appSettings/add [@ key ='MyUnknownVariable']'[C:\ MyApp \的DevOps\ConfigBundle.msbuild]
虽然我们收到警告是很好的,但我真的需要这个错误,因为这将成为我们自动构建和部署过程的一部分,所以在应用程序停止工作之前,不太可能有人发现它.
我想要一种方法将这些警告视为错误.基于我在互联网上看到的一些东西,我尝试了一个带有两个不同TreatWarningsAsErrors符号的PropertyGroup:
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
我已经尝试在命令行上设置它(我怀疑它与上面相同):
C:\MyApp\DevOps>msbuild /p:TreatWarningsAsErrors="true" ConfigBundle.msbuild
Run Code Online (Sandbox Code Playgroud)
遗憾的是,这些都不起作用; 警告继续发送.基于这一点,我猜测它是由个人MSBuild任务来尊重TreatWarningsAsErrors指令,在这种情况下,TransformXml不会.
如果我能找到一种方法来了解上一个任务是否发出警告,例如我可以做以下事情:
<Message Text="##teamcity[message text='Config Transform Failed!' status='ERROR']" Condition="$WarningOccurred == 'true'" />
Run Code Online (Sandbox Code Playgroud)
它并不完美,但肯定会阻止构建成功完成.希望有人会对此有一个有用的建议.
我已经经常使用配置转换,但我正在努力解决一点:“内部文本”而不是属性的更改。
作为示例,我在配置文件中包含以下内容(如果有人感兴趣,可以使用 Sitecore 为营销人员提供的网络表单):
<param desc="connection string">Database=sitecore_webforms;Data Source=CHANGEME;user id=CHANGEME;password=CHANGEME;Connect Timeout=30</param>
我想将其更改为正确的连接字符串。通常这将是我可以做得很好的属性的一部分,但在这种情况下却不是。
使用“vanilla”转换或Sayed Ibrahim Hashimi的 SlowCheetah 是否可以实现这一点?
我在我的Web配置和发布模式中有以下XML,我需要根据子项的name属性删除dependentAssembly部分:assemblyIdentity.我在这里尝试了答案:xdt转换定位器匹配子节点内容但没有运气.我的web.config是这样的:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.QualityTools.Resource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<codeBase version="10.0.0.0" href="file:///c:/Program%20Files%20(x86)/Microsoft%20Visual%20Studio%2010.0/Common7/IDE/PrivateAssemblies/Microsoft.VisualStudio.QualityTools.HostAdapters.ASPNETAdapter.DLL" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我在web.release.config中尝试了以下内容,根据子元素选择第二个dependentAssembly元素进行删除,但没有成功.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" >
<dependentAssembly>
<!-- Attempt 1 -->
<assemblyIdentity xdt:Transform="RemoveAll"
xdt:Locator="Condition(@name='Microsoft.VisualStudio.QualityTools.Resource')"/>
</dependentAssembly>
</assemblyBinding>
<!-- Attempt 2 -->
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xdt:Transform="Remove"
xdt:Locator="Condition(assemblyIdentity/@name='Microsoft.VisualStudio.QualityTools.Resource')">
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud) 目前我的web.config看起来像这样:
<configuration>
<connectionStrings configSource="connectionstrings.config"/>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在生成部署包(Msbuild.exe + target = Package)时,它不会"神奇地"将我的连接字符串参数化到parameters.xml文件以进行部署时的替换.
当我内联我的连接线时,一切都很好,并为我的连接线生成参数..
所以:
如何通过web.config转换复制connectionstrings.config的内容作为部署<... configsource ="xxx"/>的替换?
编辑: 我接受了Sayed Ibrahim的答案,因为'默认'行为非常好(web.config中连接字符串的自动参数化)但最后更好地指定需要参数化的确切内容(通过{projectname} .wpp.targets或parameters.xml文件).
msbuild web-config msdeploy web-config-transform config-transformation
我对这种转变很新,我不完全明白如何实现它.这些指南都没有意义.
我想补充一下
<identity impersonate="true" userName="asecret" password="mysecurepassword"/>
Run Code Online (Sandbox Code Playgroud)
到发布配置.
我之后把它放在web.release.config中,<system.web>但它不会生成.
你还想做什么?
我尝试从一个小节中获取所有属性,但该节有很多小节并且应用程序无法识别,我该怎么办?这是我的网络配置:
<configSections>
<section name="Seccion" type="ManejoConfiguracion.SeccionConfig,ManejoConfiguracion"/>
</configSections>
<Seccion>
<BD>
<add key="name" value="dbKey" />
<add key="user" value="userBD" />
<add key="pass" value="123BD" />
</BD>
<ReportingService>
<add key="name" value="Reporting" />
<add key="user" value="userReport" />
</ReportingService>
</Seccion>
</configuration>
Run Code Online (Sandbox Code Playgroud) 嗨,我想为“重定向到HTTPS”插入重写规则,但仅在我的发布配置上
这就是重写规则的样子
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to HTTPS">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
<add input="{URL}" pattern="/$" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
如何仅在我的release.config中实现此目的?
希望设置 jenkins 来部署我的网络应用程序,我正在使用脚本
msbuild WEB.csproj /p:Configuration=stage /t:Build /p:PrecompileBeforePublish=true /p:OutputPath=c:\test /p:DeployOnBuild=true /p:AutoParameterizationWebConfigConnectionStrings=False
Run Code Online (Sandbox Code Playgroud)
我获得了 Web 应用程序,_PublishedWebsite但web.config需要进行转换。有小费吗?
我需要在开发和部署期间在http和https之间切换.
为此,我需要在web.config中进行以下更改:
<behaviors>
<serviceBehaviors>
<behavior name="DirectInstallHelperServiceBehavior">
<!-- need to change to <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"> -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false">
</serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding>
<!-- need to add the following, but don't know how
<security mode="Transport">
<transport clientCredentialType="Basic"/>
</security>
-->
</binding>
</webHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
所以我尝试在Web.Release.config中添加以下行:
<behaviors>
<serviceBehaviors>
<behavior name="DirectInstallHelperServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" xdt:Transform="setAttribute(httpsGetEnabled, httpGetEnabled)" xdt:Locator="Match(name)"></serviceMetadata>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding>
<security mode="Transport" xdt:Transform="InsertAfter(/configuration/system.serviceModel/bindings/webHttpBinding/binding)">
<transport clientCredentialType="Basic"/>
</security>
</binding>
</webHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)
但我做错了,因为当我将服务发布到我的文件系统时,我仍然看到web.config的开发http版本.任何帮助表示赞赏.
web-config ×5
asp.net ×3
c# ×3
msbuild ×3
.net ×2
msdeploy ×2
asp.net-mvc ×1
jenkins ×1
wcf ×1
xslt ×1