我正在使用此问题的解决方案,以便App.config在Winforms项目中应用配置更改.我还有一个项目的安装程序项目,它创建一个可安装的*.msi文件.问题是,安装程序中捆绑的配置文件是原始的,未转换的配置文件.因此,即使构建的winforms项目的配置文件已应用了所有正确的转换,我们也无法在生产安装程序中获取生产连接字符串.
有没有办法强制安装程序项目使用项目构建的输出?
我想添加一个web.config转换,以便通过MSBuild在自动构建/部署周期中使用.但是,当我使用Visual Studio添加转换时,我只获得调试和发布,并且没有选择转换的选项.据我所知,我需要添加一个新的配置文件,但我真的不需要它.我是否必须这样做或者还有其他方法来使用转换(特别是对于构建任务)?
我也担心如果我添加一个新的配置文件,我可能会破坏检查调试配置的代码:
#if DEBUG
Run Code Online (Sandbox Code Playgroud)
这个常量是在配置文件中定义的,还是配置文件本身?
基本上我的问题是如何为自动构建添加不是调试/发布的配置变换?
我一直在关注Web配置转换的MSDN指南,并且大体上都取得了成功.
但是,我的网络配置的一行是给我的麻烦,我只能假设它是因为我误解了指南并使用了错误的语法.
我希望有人能够指出我的错误,如果是这样的话,我将不胜感激.
变换中的违规行是:
<sessionState sqlConnectionString="data source=localhost;uid=userId;pwd=password;" xdt:Transform="SetAttributes(sqlConnectionString)" />
Run Code Online (Sandbox Code Playgroud)
原始Web配置中的行是:
<sessionState mode="SQLServer" sqlConnectionString="data source=networkAlias;uid=userId;pwd=password;" cookieless="UseDeviceProfile" timeout="120" />
Run Code Online (Sandbox Code Playgroud)
我希望转换将替换属性"sqlConnectionString",改变连接细节.不幸的是,这条线不受影响.
我使用了完全相同的语法:
<network host="localhost" xdt:Transform="SetAttributes(host)" />
Run Code Online (Sandbox Code Playgroud)
上面的工作很好,所以我认为它也是如此.
谁能看到我哪里出错了?
目前,我可以根据构建配置轻松设置Web.config转换,例如使用connectionString=server;..for Debug和connectionString=./SQLExpress;..for Release.
但是有可能基于Web发布配置文件进行一些Web.config转换吗?即使用connectionString=server1;..的配置文件Server1,并connectionString=server2;..为Server2?
.net asp.net visual-studio-2010 web-config-transform msbuild-wpp
我正在使用通过VS2010提供的web.config转换.在这一个案例中,我想知道是否有可能在转换期间将一个元素"包围"另一个元素.这是一个例子:
默认的web.config包含:
<configuration>
<system.web>
....
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我的转换文件应该包含
<configuration>
<location inheritInChildApplications="false">
<system.web>
...
</system.web>
</location>
</configuration>
Run Code Online (Sandbox Code Playgroud)
所以基本上我想用一个location元素'包装'system.web元素.我唯一的想法就是做一个转换,以便我在之前和之后插入:
<location inheritInChildApplications="false"
xdt:Transform="InsertBefore(/configuration/system.web)">
</location xdt:Transform="InsertAfter(/configuration/system.web)">
Run Code Online (Sandbox Code Playgroud)
但根据VS(我猜测因为Transform属性),结束位置元素不是有效的xml.只是在system.web之前插入一个自动关闭的位置元素也无济于事,因为生成的system.web仍然没有被"包围".
我最近在visual studio 2010的web部署工具中发现了web.config自动转换.它运行良好,但我有一个我似乎无法工作的场景.假设我有以下根Web.config
<services>
<service name="Service1">
<endpoint address="" binding="customBinding" bindingConfiguration="LargeBufferBinding"
contract="Service1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="Service2">
<endpoint address="" binding="customBinding" bindingConfiguration="LargeBufferBinding"
contract="Service2" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
<service name="Service3">
<endpoint address="" binding="customBinding" bindingConfiguration="LargeBufferBinding"
contract="Service3" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
对于我的Web.Release.config,我希望删除所有带有mexHttpBinding绑定的端点节点.
我在我的Web.Release.config中使用了以下内容:
<services>
<service>
<endpoint binding="mexHttpBinding" xdt:Locator="Match(binding)" xdt:Transform="Remove" />
</service>
</services>
Run Code Online (Sandbox Code Playgroud)
但是,这只会删除Service1中的第一个匹配项,但不会删除以下匹配项.我尝试了在端点和服务节点上定位节点的各种方法,但只有第一个匹配才被替换.
有没有办法让所有<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />被删除?
谢谢.
children web-config nodes web-config-transform xdt-transform
我对此非常困惑.在我开发和使用实时SQL Server时,我想在我的桌面上使用SQL Server.我正在使用Visual Studio 2010中的转换内容.
当我尝试发布我的项目时,我得到了"匹配定位器"的"无属性"名称.
我的Web.config文件包含:
<connectionStrings>
<add name="EFDbContext" connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<sessionState mode="SQLServer" sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=eGov" timeout="20" allowCustomSqlDatabase="true" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
我还在测试它,所以现在,我的Web.Release.config文件包含:
<connectionStrings>
<add name="EFDbContext"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=db"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<sessionState mode="SQLServer"
sqlConnectionString="Server=.\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=ASPState;Application Name=app"
timeout="20" allowCustomSqlDatabase="true"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</system.web>
Run Code Online (Sandbox Code Playgroud)
我在网上看到的任何东西都让我更加困惑.有什么帮助让我起床和跑步?
我试图转换我所拥有的项目中的所有web.config文件,这是我的树结构:
还有更多的web.config文件,但我们的想法是,它会找到所有这些文件并对它们应用相同的配置转换.
我从我发现的博客文章中得到了一些提示,但是我在最后一步,即实际的转变中陷入困境.中间还有一些我不喜欢的粗略部分(我不太明白我在做什么,我显然做错了).这是我到目前为止的地方:
<Project ToolsVersion="4.0" DefaultTargets="Transform" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="Tools\Microsoft.Web.Publishing.Tasks.dll"/>
<PropertyGroup>
<SitePath>..\..\Website</SitePath>
<WebConfigTransformInputFile>$(SitePath)\Web.config</WebConfigTransformInputFile>
<WebConfigTransformFile>Web.Transform.config</WebConfigTransformFile>
<OutDir>..\N\N\</OutDir>
</PropertyGroup>
<ItemGroup>
<_FilesToTransform Include="$(SitePath)\**\web.config"/>
</ItemGroup>
<Target Name="Transform">
<MakeDir Directories="@(_FilesToTransform->'$(OutDir)%(RelativeDir)')" />
<TransformXml Source="@(_FilesToTransform->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')"
Transform="$(WebConfigTransformFile)"
Destination="@(_FilesToTransform->'$(OutDir)%(RelativeDir)%(Filename)%(Extension)')" />
</Target>
</Project>
Run Code Online (Sandbox Code Playgroud)
我的Transform.bat看起来像这样:
%systemroot%\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe %CD%\Transforms\ConfigTransform.proj
Run Code Online (Sandbox Code Playgroud)
因此,当我调用批处理时,会创建相应的目录.然而,正如你所看到的,我必须对OutDir有点创意,使它成为..\N\N.出于某种原因,如果我不这样做,OutDir路径将与输入目录完全相同.所以我显然需要在MakeDir中改变一些东西,但我不确定是什么.
真正的问题出现在它开始进行变换时.我试图保持TransformXml Source参数像这样或类似:
@(_FilesToTransformNotAppConfig->'%(FullPath)')
Run Code Online (Sandbox Code Playgroud)
后者给我一个错误"无法打开源文件:不支持给定路径的格式." 而前者给了我这个输出:
Build started 30-4-2012 14:02:48.
Project "D:\Dev\transform\DoTransforms\Transforms\ConfigTransform.proj" on node 1 (default targets).
Transform:
Creating directory "..\N\N\..\..\Website\Views\".
Transforming Source File: ..\N\N\..\..\Website\Views\Web.config;..\N\N\..\..\Website\Web.config
D:\Dev\transform\DoTransforms\Transforms\ConfigTransform.proj(32,2): error : Could not open Source file: Could not …Run Code Online (Sandbox Code Playgroud) 我有一个看起来像这样的变换
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<a>
<b>
<c>
<d>
<e name="UpdateLanguageProfile">
<f xdt:Transform="Replace" xdt:Locator="Condition(/..@name='UpdateLanguageProfile')">
stuff here
</f>
</e>
</d>
</c>
</b>
</a>
Run Code Online (Sandbox Code Playgroud)
所以我希望xdt:Locator仅在父节点具有指定值的属性时才选择f节点.
xdt:Locator被转换为以下xpath表达式:
/a/b/c/d/e/f[/..@name='UpdateLanguageProfile']
Run Code Online (Sandbox Code Playgroud)
这是无效的.
所以问题是,我可以在条件中放入什么,即XPath方括号,以便根据父节点中的属性选择f节点.
我正在使用Web.config转换来成功创建我的web.config的调试和发布版本 - 这是正常的.
我有兴趣知道是否有一个'机器名'属性来指定我可以在调试URL中使用的当前机器名,而不是硬编码特定的机器名(在这种情况下使用localhost不是一个选项) ,例如
<add name="XrmService" connectionString="http://$(ComputerName):5555/Service.svc" />
Run Code Online (Sandbox Code Playgroud)
使用Web.config转换是否有可用的属性?类似于MSBuild的$(ComputerName)财产?
web-config ×4
asp.net ×3
msbuild ×3
.net ×1
children ×1
installer ×1
msbuild-task ×1
msbuild-wpp ×1
nodes ×1
slowcheetah ×1
winforms ×1
xpath ×1