CodeAssassin.ConfigTransform for of arbitrarily named config files

拈花ヽ惹草 提交于 2019-12-13 01:27:35

问题


NuGet packages such as CodeAssassin.ConfigTransform tranform web.*.config or app.*.config to web.*.config.transformed or app.*.config.transformed upon a VS build.

However, what if you have config files of form {arbitrary-name}.config ?

For example, MyAssembly.dll.config and its transform rulesets MyAssembly.dll.debug.config & MyAssembly.dll.release.config

CodeAssassin.ConfigTransform does not appear to work for these file patterns.


回答1:


If you look at the target source code it looks quite simple to modify it to allow any .config file to be transformed. Actually I think that transforming any XML file should be possible.

I will fork that repository tomorrow for and experiment with this.




回答2:


Disclaimer: In this example I modified CodeAssassin.ConfigTransform.targets directly. But you should create a separate .targets file and reference that in your .csproj.

Add a ConnectionString.config (as an example) and then add the transforms.

Add this to the .targets file (your config name just has to match the regex expression - (?i)^ConnectionString\. in this case):

<Target Name="TransformAllConnectionStringConfigTransformFiles"
        Condition="'$(WebProjectOutputDir)'!=''"
        BeforeTargets="Compile">

  <ItemGroup>
    <ConnectionStringConfigTransformFile Include="@(None);@(Content)" Condition="'$([System.Text.RegularExpressions.Regex]::IsMatch(%(Filename),&quot;(?i)^ConnectionString\.&quot;))' == true and '%(Extension)'=='.config'" />
  </ItemGroup>

  <TransformXml Source="ConnectionString.config" Destination="%(ConnectionStringConfigTransformFile.Identity).transformed" Transform="@(ConnectionStringConfigTransformFile)"
                Condition="'@(ConnectionStringConfigTransformFile)'!=''" />

  <CreateItem Include="%(ConnectionStringConfigTransformFile.Identity).transformed"
              AdditionalMetadata="CopyToOutputDirectory=Always">
    <Output TaskParameter="Include" ItemName="Content"/>
  </CreateItem>

</Target>

Build, and your .transformed files are created.



来源:https://stackoverflow.com/questions/12683927/codeassassin-configtransform-for-of-arbitrarily-named-config-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!