New files not found by *-wildcard in MSBuild

71 views Asked by At

We have a modern .NET web application - developed in VisualStudio. A month ago, I wrote a couple of MSBuild configuration scripts to handle deployment smoothly. And they work fine. The application is published to a folder, and we just copy the folder contents to IIS.

BUT… One thing isn’t working. We minify/obfuscate JavaScript and CSS files. We set group names with definitions like this in the ".props" file:

<ItemGroup>
    <FixJsFiles Include="wwwroot/js/*.js" />
</ItemGroup>

Then we process the files like this in the ".target" file:

<Target Name="MinifyJs" AfterTargets="AfterPublish" Outputs="%(FixJsFiles.Identity)">
    <-- set some variables, like source and destination filenames -->
    <-- process the file with an Exec-command -->
</Target>

The Exec-command reads the source JavaScript file and writes a minified version of it in the publish folder.

This works file - for the files that were in the source folder when I wrote the MSBuild files... Any files added after that are not processed - they are not included in FixJsFiles, so the Target loop is only executed for the old files.

(Say I had "a.js", "b.js" and "c.js" in the folder two months ago. Then I added "d.js" last week. When publishing, the Target loop is only run three times, not for "d.js".)

I have tried lots of thing - like rebuilding the solution, of course. And the "*.js"-wildcard should be recalculated every time we publish. (Or?) But it isn't - it's stuck with the old files. Does anybody know why?

/Anders from Sweden

1

There are 1 answers

1
UglySwede On BEST ANSWER

Found it! Putting it here - it may help others.

VisualStudio has added lines to the project file - "MyProject.csproj" - to EXCLUDE the new files! Lines like these:

<ItemGroup>
  <FixJsFiles Remove="wwwroot\js\d.js" />
</ItemGroup>

I did NOT add these line, they were automatically added by VS. I see no reason for it to do so... If I add new files to a folder, I of course want those files to be included in the wildcard expansion when building the project.

Very strange! Well, removing the lines fixed the problem. Now you know where to look, if it happens to you.