我正在使用 MSBuild 扩展包替换 .proj 文件中的行。我用多行替换多行。即使我进行转换,它输出的行末尾仍然有一个分号。
<ItemGroup>
<TestFile Include="regextest.xml" />
<MyLines Include ="%3CItemGroup%3E%0A"/>
<MyLines Include ="%09%3CReference Include=%22Stuff%22%3E%0A" />
<MyLines Include ="%09%09%3CHintPath%3E..\..\packages\secret.dll%3C/HintPath%3E%0A" />
<MyLines Include ="%09%09%3CPrivate%3ETrue%3C/Private%3E%0A" />
<MyLines Include ="%09%3C/Reference%3E%0A" />
<MyLines Include ="%3C/ItemGroup%3E%0A" />
</ItemGroup>
<Target Name="Default">
<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace"
TextEncoding="ASCII"
RegexPattern="%3CProjectReference"
RegexOptionList="IgnoreCase"
Replacement="@(MyLines->'%(Identity)')"
Files="@(TestFile)" />
</Target>
这是输出:
<ItemGroup>
; <Reference Include="Stuff">
; <HintPath>..\..\packages\secret.dll</HintPath>
; <Private>True</Private>
; </Reference>
;</ItemGroup>
在没有转换的情况下进行操作仍然有它们。