Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bonus Chapter - Page 4 #9

Closed
BobMolloy opened this issue Dec 18, 2022 · 2 comments
Closed

Bonus Chapter - Page 4 #9

BobMolloy opened this issue Dec 18, 2022 · 2 comments

Comments

@BobMolloy
Copy link

BobMolloy commented Dec 18, 2022

Bullet 2:

The app.UseMiddleware statement throws this compiler error:

Error CS0246 The type or namespace name 'SecurityHeaders' could not be found
(are you missing a using directive or an assembly reference?) Northwind.WebApi
C:\cs11dotnet7\PracticalApps\Northwind.WebApi\Program.cs
77 Active

This is another example of adding a class file (SecurityHeadersMiddleware.cs) and finding that its build action is set to "None". I don't know if this is a VS2022 problem or something I'm doing incorrectly.

@markjprice
Copy link
Owner

I have not experienced VS2022 setting a file build action to None by default.

I found this StackOverflow item by Googling but it is old and I never like messing around with the registry. https://stackoverflow.com/questions/747844/default-build-action-for-a-filetype

It might be worth you experimenting with creating new projects and adding various file types and immediately seeing what the settings are in Properties window and comparing that to the .csproj file.

For example, adding a C# class file named SecurityHeadersMiddleware.cs to an ASP.NET Core project should default its Build Action to C# compiler and no entry for it should be made in the .csproj file. But if the Build Action for that file is changed to None then the following entries are added to the .csproj file:

  <ItemGroup>
    <Compile Remove="SecurityHeadersMiddleware.cs" />
  </ItemGroup>

  <ItemGroup>
    <None Include="SecurityHeadersMiddleware.cs" />
  </ItemGroup>

I will think about how to add a section to the next edition about build actions, especially in ASP.NET Core projects, since it'd be a useful topic for all readers to be aware of.

@BobMolloy
Copy link
Author

OK, we might as well write this one off. I'll try to keep an eye on the properties when I add a new file to a project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants