问题
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),"(?i)^ConnectionString\."))' == 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