Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude certain file types from dotnet watch run?

Looking to get the following setup going:

I'm working on a Blazor app, and with the official css isolation bundler. I'm using Less though, and installed a Less transformer which creates the required css on build.

However, running my app via dotnet watch run, it often ends up in an endless loop now.

The reason for this is probably that dotnet watch run sees a change in the *.razor.css files, rebuilds, and the cycle just repeats on and on.

So here's my question:

How can I configure my csproj (new Net Standard format) to exclude **\*.razor.css from the watch process? It would also be fine it it just disappears from my VS solution as a whole.

like image 644
Sossenbinder Avatar asked Dec 20 '20 02:12

Sossenbinder


3 Answers

Had a play with both answers above, but neither worked for me. I generate some files during the build and that may be why the other 2 don't work for me. According to Microsoft docs shared above (https://learn.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-3.1), to remove an item from watch you can also set it through the definition. Doing this worked for my scenario.

<ItemGroup>
    <Content Remove="wwwroot\dist\**" />
    <Content Include="wwwroot\dist\**" Watch="false" />
</ItemGroup>

I did have to add the Content Remove as otherwise the item is declared twice and the build will fail.

like image 52
Herman Vos Avatar answered Oct 20 '22 05:10

Herman Vos


Please edit your .csproj file and add the following to it

<ItemGroup>  
    <Watch Exclude="**\*.razor.css" />
</ItemGroup>

More info at

https://learn.microsoft.com/en-us/aspnet/core/tutorials/dotnet-watch?view=aspnetcore-3.1

like image 45
ademg Avatar answered Oct 20 '22 05:10

ademg


I had the same issue after coming here, ended up with:

<ItemGroup>
    <Watch Remove="wwwroot\**\*" />
</ItemGroup>

Works nicely for me :)

like image 1
McKnight Avatar answered Oct 20 '22 05:10

McKnight