Daily Usage Issues

What triggers a build?

Started by MikeWard on 12,700 views

I have a Web application written in C# (server) and Typescript (client). I use a single .csproj in this instance.

I've excluded *.js and *.ts files in my NCrunch settings but whenever I edit/save Typescript files, NCrunch builds/tests the C# code.

Is there a way to determine what triggers the NCrunch build?
Hi, thanks for posting.

Normally, NCrunch's Files Excluded From Auto Build setting should restrict the engine from automatically firing off if you make a text change to any file type specified by this setting.

If you are running any other kind of tool that may derive files from your .ts or .cs files, it's possible that this could then trigger the build indirectly.

Does this happen for you on any code that you can share with me? For example, if you create a sample web project with a .cs and .ts file and set these up in the file build exclusions, does the engine work as it should?

Something to be careful with is that this is a project-level config setting (rather than global or solution-wide), so you'll need to apply it to every project you need it to work for.
I agree that it's likely some other tooling changing something and triggering the build. I'll see if I can put together a sample project that illustrates the problem.

Of course, this is totally your fault. If you hadn't made it so easy run tests I wouldn't have written so many and this wouldn't be a problem. :)
MikeWard wrote:I agree that it's likely some other tooling changing something and triggering the build. I'll see if I can put together a sample project that illustrates the problem.


It could still be NCrunch .. but we won't know until we isolate it. Do let me know if you learn anything more about it.

MikeWard wrote:
Of course, this is totally your fault. If you hadn't made it so easy run tests I wouldn't have written so many and this wouldn't be a problem. :)


Feels like there's no way I can win :)
This post has been deleted.
OK, I figured out the issue.

My folder structure for Typscript is:

\myproject\js\apps\...

The output folder for Typescript is:

\myproject\js\bin\

This is where the outputs for Typescript go (bundle.js and bundle.js.map).

Deleting a file in the \myproject\js\bin folder triggers an NCrunch build.

Could it be my choice of folder name here (bin)?

P.S. Renamed the bin folder to "out". Had to change a bunch of references in the project and build scripts but afterwards, things work as expected. Editing *.ts files does not trigger an NCrunch build/test cycle.

Edited

Well, this is annoying. It worked for a few hours and now the behavior is back. I can delete the bundle.js file from the out folder and NCrunch builds.
It looks like something isn't right with the files you have included in the workspace. You'll want to avoid including derived files in the workspace where possible. Check for broad use of the 'Additional files to include' setting.

From memory, the 'Files excluded from auto-build' setting was intended to exclude file edits from the auto build feature. If files are physically removed from the project, this is considered to be a project change rather than a file change (as it impacts the project XML). When a project is changed, NCrunch must rebuild the project regardless of how you are using the setting.
OK, I see the problem. I need to include the bundle.js and bundle.js.map files in my project so the Visual Studio Publish Profile will use them. It feels like I need a, "consider these files as not part of the solution" option.
MikeWard wrote:OK, I see the problem. I need to include the bundle.js and bundle.js.map files in my project so the Visual Studio Publish Profile will use them. It feels like I need a, "consider these files as not part of the solution" option.


There is a way we can do this :)

Where the files are declared inside your Build XML, for example:

<ItemGroup>
<None Include="bundle.js" />
<None Include="bundle.js.map" />
</ItemGroup>

You can exclude them for NCrunch with a condition:

<ItemGroup>
<None Include="bundle.js" Condition="'$(NCrunch)' != '1'" />
<None Include="bundle.js.map" Condition="'$(NCrunch)' != '1'" />
</ItemGroup>

Or alternatively:

<ItemGroup Condition="'$(NCrunch)' != '1'">
<None Include="bundle.js" />
<None Include="bundle.js.map" />
</ItemGroup>

The files will then be detected by the IDE and VS publish, but excluded from NCrunch.

added to my .csproj:

<ItemGroup Condition="'$(NCrunch)' != '1'">
<None Include="js\out\bundle.js" />
<None Include="js\out\vendor.js" />
<None Include="js\out\vendor.css" />
</ItemGroup>

When I delete js\out\bundle.js NCrunch builds/tests.
MikeWard wrote:
When I delete js\out\bundle.js NCrunch builds/tests.


Are you making use of the 'Additional files to include' setting at all? Do you know if there are any other references to this file through your project structure?

A good way to test whether NCrunch is still including the file in its workspace is to break this project so it won't build (or copy/produce the .js files in your out dir), then reset the engine. You can then inspect the workspace by going through the Advanced->Browse to workspace option in the Tests Window. Is the file shown in the workspace? If so, that means NCrunch will likely have identified it as a dependency and copied it. If not, there may be something else watching this file that is triggering NCrunch.
Here's a very small VS solution I threw together that demonstrates the issue.

(- BROKEN LINK -)

Once setup (see README.md) you can edit the itunes-app.ts file. Save it and NCrunch builds.

P.S. Just noticed I left a syntax error in Bootstrapper.cs trying your earlier suggestion.

Edited

Thanks for the sample project.

In this case, NCrunch's build is being triggered by the derived files from the typescript auto generation. When you hit save, typescript is automatically running code over the .ts files to generate outputs. Because these outputs are included in your project file, NCrunch is watching them for changes and will trigger when they are modified on disk.

I was able to suppress this behaviour with the following modifications made to the project file:

<ItemGroup>
<Content Include="Content\nancy-logo.png" />
<None Condition="'$(NCrunch)' != '1'" Include="Content\out\bundle.js" />
<None Condition="'$(NCrunch)' != '1'" Include="Content\out\vendor.css" />
<None Condition="'$(NCrunch)' != '1'" Include="Content\out\vendor.js" />
<Content Include="Web.config" />
</ItemGroup>

Edit: I'd like to add that this does actually look like a bug in NCrunch. The 'Files excluded from auto build' is only being applied to changes that come from the IDE, not from the file system. It seems like it should work for both. I've noted this down for review.

Edited

v2.25 has just been released, including a fix for the 'Files excluded from auto build' setting not working for file system changes.

Post a reply

Log in to reply.