【问题标题】:Is it possible to do text manipulation in csproj?是否可以在 csproj 中进行文本操作?
【发布时间】:2019-05-16 06:17:39
【问题描述】:

我的.csproj 中有以下内容:

<ItemGroup>
  <Content Include="Main.qml" CopyToPublishDirectory="Always" />
</ItemGroup>

我需要在已发布目录的副本上查找并替换 Main.qml 中的一些文本。这可能吗?

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 您是否探索过 Visual Studio 中的构建后事件?
  • 谢谢!这就是我一直在寻找的。您可以将其添加为答案以便我接受吗?

标签: c# csproj


【解决方案1】:

MSBuild Extension Pack 有一个File 类,它接受TaskActionReplace。此操作可以执行正则表达式替换。

你会像这样使用它:

<MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" RegexPattern="input*" Replacement="repl" Path="C:\$(ProjectDir)\$(PublishDir)\Main.qml"/>

【讨论】:

    【解决方案2】:
    <postBuild>
        <Exec command="cmd command to find and replace on file:$(OutputPath)\Main.qml"/>
    </PostBuild>
    

    【讨论】:

    • 对不起,我是手机端的。稍后我会详细说明。
    • 我希望它是跨平台的,所以最好是使用构建工具而不是依赖主机系统中的二进制文件。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 2023-02-09
    • 2015-11-20
    • 2013-11-03
    相关资源
    最近更新 更多