0
먼저 http://regexpal.com/과 같은 온라인 도구에서 텍스트의 첫 번째 항목 만 바꾸고이 항목이 MSBUILD 작업에서 작동하는지 확인하려고합니다.RegEX - 첫 번째 텍스트 만 바꾸기
난과 같이 .NET에서 원하는 것을 할 수 있습니다 MSBUILD 작업이 작업을 얻을 언급 한 바와 같이
StringBuilder sb = new StringBuilder();
sb.Append("IF @@TRANCOUNT>0 BEGIN");
sb.Append("IF @@TRANCOUNT>0 BEGIN");
sb.Append("IF @@TRANCOUNT>0 BEGIN");
Regex MyRgx = new Regex("IF @@TRANCOUNT>0 BEGIN");
string Myresult = MyRgx.Replace(sb.ToString(), "foo", 1);
내 궁극적 인 목표입니다. 내가 온 가장 가까운 (인정 하듯이 종료되지 않은!)
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<ItemGroup>
<SourceFile Include="source.txt" />
<FileToUpdate Include="FileToUpdate.txt" />
</ItemGroup>
<Target Name="go">
<!-- a) Delete our target file so we can run multiple times-->
<Delete Files="@(FileToUpdate)" />
<!-- b) Copy the source to the version we will amend-->
<Copy SourceFiles= "@(SourceFile)"
DestinationFiles="@(FileToUpdate)"
ContinueOnError="false" />
<!-- c) Finally.. amend the file-->
<FileUpdate
Files="@(FileToUpdate)"
Regex="IF @@TRANCOUNT>0 BEGIN(.+?)"
ReplacementText="...I have replaced the first match only..."
Condition=""/>
<!-- NB The above example replaces ALL except the last one (!)-->
</Target>
</Project>
감사
정규식에서
, 그리고 헤이 프레스토! $ 2가 작동하게 만드는 것은 무엇입니까? –
$ 1, $ 2 등은 정규식에서 찾은 캡처이므로 $ 2는'(. *)'- "IF @@ TRANCOUNT> 0 BEGIN' 이후" – Lanorkin
감사합니다 :) [캡처에서 읽으 려합니다. ..] –