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

后端 未结 4 1643
谎友^
谎友^ 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:55

    You could extend the .csproj with a small snippet that will generate a warning when an item in the "None" group has the extension .cshtml. The snippet would be:

    
      
        
      
      
    
    

    If you see other build actions (like EmbeddedResource), you can add them to the Filtered item definition.

    If you want more advanced detection you need to actually parse the project files for any item that fits this Xpath //ItemGroup/*[not(self::Content)]/@Include

    
      
        
      
    
      
      
        
      
    
      
    
    

    Instead of you can also use

    You'll need to manually put one of these snippets in your project file:

    enter image description here

提交回复
热议问题