Created
November 19, 2022 21:46
-
-
Save atcarter714/83231e87841d2021137cebb97b7eeb22 to your computer and use it in GitHub Desktop.
Defines a custom Directory.Build.props file for large, SDK-style projects in Visual Studio 2022 + MSBuild with custom intermediate and build output directories (W.i.P.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<!--Version 0.1.2 of Directory.Build.props--> | |
<!-- Additional Solution Properties and Info --> | |
<PropertyGroup Label="ExtraInfo"> | |
<OwnerName>Yourfirst McLastname, Jr.</OwnerName> | |
<Developers>$(OwnerName);</Developers> | |
<DevGitHubPage>https://github.com/atcarter714</DevGitHubPage> | |
<CompanyWebsite>https://github.com/atcarter714</CompanyWebsite> | |
<Company>$(OwnerName)</Company> | |
<Authors>$(Developers)</Authors> | |
<Copyright>Copyright © 2022 Aaron T. Carter, AtC. All rights reserved.</Copyright> | |
<SDKName>ExampleSDK</SDKName> | |
<ProductName>$(SDKName)</ProductName> | |
<SDKDesc>A powerful example SDK with incredible performance and a coffee maker!</SDKDesc> | |
<RepositoryType>git</RepositoryType> | |
<RepositoryUrl>$(DevGitHubPage)/</RepositoryUrl> | |
</PropertyGroup> | |
<!--Define the common paths and output directories--> | |
<PropertyGroup Label="SolutionPaths"> | |
<!-- Define common directories --> | |
<RepoRootPath>$(MSBuildThisFileDirectory)</RepoRootPath> | |
<BinDir>$(RepoRootPath)bin</BinDir> | |
<ObjDir>$(RepoRootPath)obj</ObjDir> | |
<DocDir>$(RepoRootPath)doc</DocDir> | |
<FileDir>$(RepoRootPath)file</FileDir> | |
<SourceDir>$(RepoRootPath)src</SourceDir> | |
<!-- Project build/output paths: --> | |
<BaseOutputPath>$(BinDir)\$(Configuration)\$(TargetFramework)</BaseOutputPath> | |
<BaseIntermediateOutputPath>$(ObjDir)\$(MSBuildProjectName)</BaseIntermediateOutputPath> | |
<PackageOutputPath>$(BinDir)\Packages\$(Configuration)\$(TargetFramework)</PackageOutputPath> | |
<MSBuildProjectExtensionsPath>$(BaseIntermediateOutputPath)</MSBuildProjectExtensionsPath> | |
<ProjectAssetsFile>$(BaseIntermediateOutputPath)\project.assets.json</ProjectAssetsFile> | |
<!--NOTE: Should MSBuild add subfolders to output paths? | |
Be advised that MSBuild will, by default, try to automatically add subdirectories | |
to your custom output paths like a target framework or runtime version name ... | |
This can screw up your intended file/folder structure for your builds and cause | |
you to end up with extra/repeating sub-folders and things ending up in strange, | |
deeper-level directories instead of where they belong, and is very annoying ... | |
Setting these properties to "false" will prevent this from happening to you ... --> | |
<!--Disable MSBuild defaults that add framework/runtime subdirectories--> | |
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | |
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath> | |
</PropertyGroup> | |
<!-- Define common build settings and properties --> | |
<PropertyGroup Label="CommonBuildSettings"> | |
<!-- Target platforms, frameworks and build configuration --> | |
<TargetFrameworks>net6.0;net7.0;</TargetFrameworks> | |
<!-- Compiler settings and options --> | |
<LangVersion>latest</LangVersion> | |
<Nullable>enable</Nullable> | |
<ImplicitUsings>true</ImplicitUsings> | |
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | |
<!--Build events and update checking--> | |
<RunPostBuildEvent>Always</RunPostBuildEvent> | |
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck> | |
<!-- Code Analysis and Refactoring Settings --> | |
<AnalysisLevel>latest</AnalysisLevel> | |
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> | |
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild> | |
<RootNamespace>ExampleSDK</RootNamespace> | |
<GenerateDocumentationFile>true</GenerateDocumentationFile> | |
<IsTestProject>$(AssemblyName.Contains('Test'))</IsTestProject> | |
<IsLibrary Condition="'$(TargetType)'=='Library'" /> | |
<IsDotNetCore Condition="'$(MSBuildRuntimeType)'!='Core'" /> | |
<DocumentationFile>$(DocDir)\$(AssemblyName)\</DocumentationFile> | |
<!-- Share one, common version.json file with all projects in a large build. --> | |
<GitVersionBaseDirectory>$(MSBuildThisFileDirectory)</GitVersionBaseDirectory> | |
<!-- Local builds should embed PDBs so we never lose them when a subsequent build occurs. --> | |
<DebugType Condition=" '$(CI)' != 'true' and '$(TF_BUILD)' != 'true' ">embedded</DebugType> | |
<!-- Signing Strongly-Named Assemblies --> | |
<!--<SignAssembly>true</SignAssembly> | |
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)file\keys\strongname.snk</AssemblyOriginatorKeyFile>--> | |
<!--Package Reference Properties--> | |
<!--<PackageReference Include="xxx" Version="0.7.4" Condition="'$(MSBuildRuntimeType)'!='Core'" />--> | |
</PropertyGroup> | |
<!-- NuGet Package Build Settings --> | |
<!--<PropertyGroup Label="PackageOutputProps"> | |
<PackageProjectUrl>https://github.com/atcarter714/the_package_url/</PackageProjectUrl> | |
<PublishRepositoryUrl>true</PublishRepositoryUrl> | |
<EmbedUntrackedSources>true</EmbedUntrackedSources> | |
<IncludeSymbols Condition=" '$(DebugType)' != 'embedded' ">true</IncludeSymbols> | |
<SymbolPackageFormat>snupkg</SymbolPackageFormat> | |
</PropertyGroup>--> | |
<PropertyGroup Label="Hacks"> | |
<!-- WARNING: This pattern is there to ignore folders such as .git and .vs, | |
but it will also match items included with a relative path outside the | |
project folder (for example "..\Shared\Shared.cs"). So be sure only to | |
apply it to items that are in the project folder. Support both | |
DefaultItemExcludesInProjectFolder and DefaultExcludesInProjectFolder | |
properties because of a naming mistake. --> | |
<DefaultExcludesInProjectFolder>$(DefaultExcludesInProjectFolder);$(DefaultItemExcludesInProjectFolder);**/.*/**</DefaultExcludesInProjectFolder> | |
</PropertyGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
About:
Directory.Build.props is a special file that will be picked up by Visual Studio and the MSBuild engine when building projects, and it applies a set of common properties to projects across the board (or certain ones, based on how you design this file!) and allows for easier setup of larger "SDK-style" solutions where multiple projects co-exist in one solution. One of the common motivations for using a Directory.Build.props is so that you can have projects nested at different levels within an "src" or "source" folder, but also output your builds of each one to a common intermediate and build output directory, such as having your own custom "bin" and "obj" folders. You can accomplish all of this with this type of file, and a custom targets file can also be used to do even more with customization of the build process ...
Feel free to copy and edit to your liking and your needs, for use in all of your SDK-style Visual Studio / MSBuild solutions and projects ... note that the copyright string in the file is OK to change to your own for your project and you have my full permission and blessing to copy and modify this file as you please (it's the whole point of sharing this).
Suggestions & Improvements?
If you have any ideas for suggestions, improvements, etc I would love to hear them! Please leave a comment and let me know how you think this could be made into a better re-usable, general-purpose Directory.Build.props template for Visual Studio solutions!