简体   繁体   English

如何从 BeforeBuild 任务中的 csproj 文件中删除节点?

[英]How to Remove node from csproj file in BeforeBuild Task?

One of my 3rd party libraries has a license file that it always adds to the csproj file each time we load the designer in VS.我的第 3 方库之一有一个许可证文件,每次我们在 VS 中加载设计器时,它都会添加到 csproj 文件中。 If I simply ignore the file, I still need to delete in VS from the Solution Explorer and I tend to forget before pushing to our source control as it is not needed.如果我只是忽略该文件,我仍然需要在 VS 中从解决方案资源管理器中删除,并且在推送到我们的源代码控制之前我往往会忘记,因为它不需要。 If there a way to remove the entry in the BeforeBuild target or similar if it is found?如果找到了 BeforeBuild 目标或类似目标中的条目,是否有办法删除它?

Below is what I'm looking to remove on each build during a build:以下是我希望在构建期间在每个构建中删除的内容:

<ItemGroup>
...
   <EmbeddedResource Include="Properties\licenses.licx" />
...
</ItemGroup>

this is a good start, but I could not figure out how to modify for my needs: Remove MSBuild DLL reference regardless of version (by wildcard) in VS 2015这是一个好的开始,但我不知道如何根据我的需要进行修改: 在 VS 2015 中删除 MSBuild DLL 引用而不考虑版本(通过通配符)

You could create a property setted on the configuration and test the condition to include the file您可以创建在配置上设置的属性并测试条件以包含文件

Like this :像这样 :

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <WithLicense>1</WithLicense>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <WithLicense>0</WithLicense>
</PropertyGroup>
<ItemGroup>
    ...
    <EmbeddedResource Include="Properties\licenses.licx" Condition="$(WithLicense)==1"/>
    ...
</ItemGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM