What is the best practice to exclude certain targets when in test? #6619
-
I have several blazor projects that reference the same c# library. That library runs some gulp tasks, that take a long time (compilation of css, sass, etc). These are completely useless during tests, so I would like to skip them, when tests are executed. Now I tried with passing a variable to the project like this from my <Project Sdk="Microsoft.NET.Sdk.Razor" InitialTargets="InformAboutTest">
<Target Name="InformAboutTest" BeforeTargets="Build">
<MSBuild Projects="MyProject.csproj" Properties="IsUnderTest=true;" />
</Target> I added this to <Target Name="DebugRunGulp" BeforeTargets="DebugEnsureNodeEnv" Condition=" '$(Configuration)' == 'Debug' And Exists('$(SolutionDir)node_modules') ">
<Message Importance="high" Text="MyProject, IsUnderTest=$(IsUnderTest)"/>
<Exec WorkingDirectory="$(SolutionDir)" Command="npm run gulp:components" />
</Target> and when I run the tests I get this output:
It seems that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
A few comments:
Can you instead add incremental build support for those things so that they are skipped when not necessary, either with MSBuild-level
Does this project also have a
The most direct way to implement what you're doing is to tell the ProjectReference to pass your special property along: <ProjectReference Include="..\MyProject\MyProject.csproj" AdditionalProperties="IsUnderTest=true" /> HOWEVER, that will cause a build race condition if you ever build a solution or traversal project that references both your test project and your library, because the solution->library reference will race with the "special" test->library reference. |
Beta Was this translation helpful? Give feedback.
A few comments:
Can you instead add incremental build support for those things so that they are skipped when not necessary, either with MSBuild-level
Inputs
andOutputs
around theTask
or with Gulp's incremental functionality? That will help for non-test build scenarios too.Does this project also …