简体   繁体   中英

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. 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. If there a way to remove the entry in the BeforeBuild target or similar if it is found?

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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