Skip to content

Commit

Permalink
Build: automatically include a parent Directory.Build.props if we are…
Browse files Browse the repository at this point in the history
… used as a sub-module

- when using this repository as a sub-module to build from source, this makes it possible to override the target framework versions from the outside
- only include the parent file if it exsists, and if it looks like we are in a sub-module (to mitigate any possible attack where an attacker would be able to inject a malicious props file in the parent folder of the CI worker)
- to detect that we are in a sub-module, we use the fact that the `.git` is a file for sub-modules, and a directory for top-level modules.
  • Loading branch information
KrzysFR committed Dec 13, 2024
1 parent bddbffb commit 832bb41
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<Project>

<!-- Detect if we are used as a submodule in a parent repository, and if this is true, try to import the parent Directory.Build.props folder that could override the properties defined here -->
<!-- We use the fact that git-submodules have a .git _file_, instead of a .git _directory_, which can help prevent from an attacker somehow being able to inject a fake .props file above us -->
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))"
Condition="Exists('$(MSBuildThisFileDirectory)../Directory.Build.props') AND $([System.IO.File]::Exists('$(MSBuildThisFileDirectory)/.git'))" />

<PropertyGroup>
<ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

<!--
These settings are used by all other projects to define the build target.
When this repository is included as a submodule, the parent folder can override these values
in its own Directory.Build.props file, in order to not have to build extra targets that are not used.
-->
<PropertyGroup>
<!-- Framework versions for the core libraries (Core, FoundationDb.Client, ...) -->
<CoreSdkRuntimeVersions Condition="'$(CloudSdkRuntimeVersions)' == ''">net9.0;net8.0</CoreSdkRuntimeVersions>
Expand All @@ -13,4 +25,5 @@
<!-- Framework versions for Aspire (only .NET8+) -->
<CloudSdkRuntimeVersions Condition="'$(CloudSdkRuntimeVersions)' == ''">net9.0;net8.0</CloudSdkRuntimeVersions>
</PropertyGroup>

</Project>

0 comments on commit 832bb41

Please sign in to comment.