{
  "$type": "site.standard.document",
  "canonicalUrl": "https://johnnyreilly.com/posts/directory-build-props-c-sharp-9-for-all",
  "description": "Learn how to use C# 9 with .NET Core by creating a `Directory.Build.props` file. All projects in the solution will support C#9 with no further steps.",
  "path": "/posts/directory-build-props-c-sharp-9-for-all",
  "publishedAt": "2021-07-14T00:00:00.000Z",
  "site": "at://did:plc:yy3apqjlms24kso7ahn7lbmb/site.standard.publication/3mova7c4nho2b",
  "tags": [
    "c#",
    "asp.net"
  ],
  "textContent": ".NET Core can make use of C9 by making some changes to your .csproj files. There is a way to opt all projects in a solution into this behaviour in a _single_ place, through using a Directory.Build.props file and / or a Directory.Build.targets file. Here's how to do it.\n\n\n\n\"have you the good news about Directory.Build.props\"?\n\nI wrote recently about using C9 with in-process Azure Functions. What that amounted to, was using C9 with .NET Core.\n\nOne of the best things about blogging, is all that you get to learn along the way. After I put up that post, Daniel Earwicker was kind enough to send this message:\n\n[](https://twitter.com/danielearwicker/status/1412678642203828226)\n\nI was intrigued that Daniel was able to configure all the projects in a solution to use the same approach using some strange incantations named Directory.Build.props and Directory.Build.targets. Microsoft describes them thusly:\n\n> Prior to MSBuild version 15, if you wanted to provide a new, custom property to projects in your solution, you had to manually add a reference to that property to every project file in the solution. Or, you had to define the property in a .props file and then explicitly import the .props file in every project in the solution, among other things.\n>\n> However, now you can add a new property to every project in one step by defining it in a single file called Directory.Build.props in the root folder that contains your source.\n\nLet's see if we can put it to use.\n\nDirectory.Build.props: C9 for all\n\nSo, rather than us updating each of our .csproj files, we should be able to create a Directory.Build.props file to sit alongside our .sln file in the root of our source code. We'll add this into the file:\n\nNow we're free to add projects into the solution, which will _already_ support C9 without us taking any further steps. It's as simple as that! Thanks to Daniel for sharing this super handy tip. ❤️🌻",
  "title": "Directory.Build.props: C# 9 for all your projects"
}