I have a .csproj
file with multiple targets. It starts like that:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net35;net40;net45;netcoreapp2.0;netstandard2.0</TargetFrameworks>
...
It is a C# project that uses Selenium, and need to update javascript file automatically using NPM. Each such javascript file should be marked as Embedded Resource
.
I tried several ways to run NPM before build. I tried writing a batch file that runs before the build, I tried installing Nuget extension to update the NPM, and even tried to add a pre-build event that updates the files.
Problem is, it happens per target, while I only need it to happen once, before the build starts.
I searched all the relevant MSBuild docs Microsoft provides looking for a solution but in vain.
Currently I update the scripts like this:
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="cd $(ProjectDir)Properties\NodeResources
call npm update && copy node_modules\mycompany\firstpackage\dist ..\Resources && copy node_modules\mycompany\secondpackage\dist ..\Resources" />
</Target>
<ItemGroup>
<None Remove="Properties\Resources\script1.js" />
<None Remove="Properties\Resources\script2.js" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Properties\Resources\script1.js" />
<EmbeddedResource Include="Properties\Resources\script2.js" />
</ItemGroup>
Anyone has an idea how to do this?