Make sure all *.cshtml files are set to be “Content” for Build Action

后端 未结 4 1646
谎友^
谎友^ 2021-02-01 15:28

A few times when I copy-paste *.cshtml files, Visual Studio for some reason sets Build Action on these files to be \"None\":

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 15:35

    Well, @jessehouwing 's certainly worked for me! So that fix stays nicely in my .csproj file :).... Only, I just double-checked and it looks as if that nice snippet disappeared somewhere in the last month due to a merge of another developer or something.. (true story)

    NPM alternative

    Anyway, I would like to mention the NPM module check-vs-includes I created for this. It is especially convenient for dev's that have Node installed (and if you don't then you probably should :) ).

    I run the check manually before each deploy, instead of on every build. But it is less likely to disappear (unnoticed) from your .csproj file due to a merge.

    The main advantage however of using this NPM package, is that besides checking for Build Action NONE it also checks for files that are NOT included in your project at all. Because that can also lead to (subtle but nasty) bugs when you use Visual Studio's Web Deploy. And missing includes are actually pretty likely if: 1) you have 1 non VS developers in your team, or 2) due to merges of the .csproj file (which often has merge issues).

    Check the NPM page for instructions. But below a simple example, which assumes you use Node and Gulp:

    Simple example

    1. Install the Node module

      npm i check-vs-includes

    2. Add a task to your gulpfile.js:

         var checkVSIncludes = require('check-vs-includes');
    
         ...
    
         gulp.task('checkVSIncludes', function() {
            checkVSIncludes(['/Views/**/*.cshtml', '/app/**/*.js']);
         });
    
    1. Run the check in your project folder (e.g. where your .csproj file is)

      gulp checkVSIncludes

提交回复
热议问题