|
| 1 | +<?xml version="1.0" encoding="utf-8"?> |
| 2 | +<Project InitialTargets="ShowCBTParseErrors;RestoreCBTModules" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
| 3 | + |
| 4 | + <PropertyGroup> |
| 5 | + <!-- Ensures that if this file changes, projects will be rebuilt --> |
| 6 | + <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects> |
| 7 | + |
| 8 | + <EnlistmentRoot Condition=" '$(EnlistmentRoot)' != '' ">$(EnlistmentRoot.TrimEnd('\\'))</EnlistmentRoot> |
| 9 | + |
| 10 | + <!-- Default CBT global to this directory if not specified --> |
| 11 | + <CBTGlobalPath Condition=" '$(CBTGlobalPath)' == '' ">$(MSBuildThisFileDirectory)</CBTGlobalPath> |
| 12 | + <CBTGlobalPath>$(CBTGlobalPath.TrimEnd('\\'))</CBTGlobalPath> |
| 13 | + |
| 14 | + <!-- Default CBT local to ..\Local if not specified --> |
| 15 | + <CBTLocalPath Condition=" '$(CBTLocalPath)' == '' And Exists('$([System.IO.Path]::GetDirectoryName($(CBTGlobalPath)))\Local') ">$([System.IO.Path]::GetDirectoryName($(CBTGlobalPath)))\Local</CBTLocalPath> |
| 16 | + <CBTLocalPath>$(CBTLocalPath.TrimEnd('\\'))</CBTLocalPath> |
| 17 | + |
| 18 | + <CBTLocalBuildExtensionsPath Condition=" '$(CBTLocalBuildExtensionsPath)' == '' And '$(CBTLocalPath)' != '' And Exists('$(CBTLocalPath)\Extensions') ">$(CBTLocalPath)\Extensions</CBTLocalBuildExtensionsPath> |
| 19 | + |
| 20 | + <DefaultProjectConfiguration Condition=" '$(DefaultProjectConfiguration)' == '' ">Debug</DefaultProjectConfiguration> |
| 21 | + <Configuration Condition=" '$(Configuration)' == '' And '$(DefaultProjectConfiguration)' != '' ">$(DefaultProjectConfiguration)</Configuration> |
| 22 | + <Platform Condition=" '$(Platform)' == '' And '$(DefaultProjectPlatform)' != '' ">$(DefaultProjectPlatform)</Platform> |
| 23 | + </PropertyGroup> |
| 24 | + |
| 25 | + <Import Project="$(CBTLocalBuildExtensionsPath)\Before.$(MSBuildThisFile)" Condition=" '$(CBTLocalBuildExtensionsPath)' != '' And Exists('$(CBTLocalBuildExtensionsPath)\Before.$(MSBuildThisFile)') " /> |
| 26 | + |
| 27 | + <PropertyGroup> |
| 28 | + <CBTModulePackageConfigPath Condition=" '$(CBTModulePackageConfigPath)' == '' And '$(CBTLocalPath)' != '' And Exists('$(CBTLocalPath)\CBTModules\CBTModules.proj') ">$([System.IO.Path]::Combine($(CBTLocalPath), 'CBTModules', 'CBTModules.proj'))</CBTModulePackageConfigPath> |
| 29 | + <CBTModulePackageConfigPath Condition=" '$(CBTModulePackageConfigPath)' == '' And '$(CBTLocalPath)' != '' And Exists('$(CBTLocalPath)\CBTModules.proj') ">$([System.IO.Path]::Combine($(CBTLocalPath), 'CBTModules.proj'))</CBTModulePackageConfigPath> |
| 30 | + <CBTModulePackageConfigPath Condition=" '$(CBTModulePackageConfigPath)' == '' And '$(CBTLocalPath)' != '' And Exists('$(CBTLocalPath)\CBTModules\packages.config') ">$([System.IO.Path]::Combine($(CBTLocalPath), 'CBTModules', 'packages.config'))</CBTModulePackageConfigPath> |
| 31 | + <CBTModulePackageConfigPath Condition=" '$(CBTModulePackageConfigPath)' == '' And '$(CBTLocalPath)' != '' And Exists('$(CBTLocalPath)\packages.config') ">$([System.IO.Path]::Combine($(CBTLocalPath), 'packages.config'))</CBTModulePackageConfigPath> |
| 32 | + <CBTModulePackageConfigPath Condition=" '$(CBTModulePackageConfigPath)' != '' ">$([System.IO.Path]::GetFullPath($(CBTModulePackageConfigPath)))</CBTModulePackageConfigPath> |
| 33 | + </PropertyGroup> |
| 34 | + |
| 35 | + <PropertyGroup> |
| 36 | + <CBTCoreAssemblyPath Condition=" '$(CBTCoreAssemblyPath)' == '' ">$(MSBuildThisFileDirectory)CBT.Core.dll</CBTCoreAssemblyPath> |
| 37 | + <CBTModuleRestoreInputs Condition=" '$(CBTModuleRestoreInputs)' == '' ">$(MSBuildThisFileFullPath);$(CBTCoreAssemblyPath);$(CBTModulePackageConfigPath)</CBTModuleRestoreInputs> |
| 38 | + </PropertyGroup> |
| 39 | + |
| 40 | + <!-- Load modules --> |
| 41 | + |
| 42 | + <PropertyGroup Condition=" '$(EnlistmentRoot)' != '' And '$(CBTModulePackageConfigPath)' != '' "> |
| 43 | + <CBTIntermediateOutputPath Condition=" '$(CBTIntermediateOutputPath)' == '' ">$(MSBuildThisFileDirectory)obj</CBTIntermediateOutputPath> |
| 44 | + |
| 45 | + <CBTModulePath Condition=" '$(CBTModulePath)' == '' ">$(CBTIntermediateOutputPath)\Modules</CBTModulePath> |
| 46 | + <CBTModulePropertiesFile Condition=" '$(CBTModulePropertiesFile)' == '' ">$(CBTModulePath)\$(MSBuildThisFile)</CBTModulePropertiesFile> |
| 47 | + <CBTModuleExtensionsPath Condition=" '$(CBTModuleExtensionsPath)' == '' ">$(CBTModulePath)\Extensions</CBTModuleExtensionsPath> |
| 48 | + <CBTModuleImportsBefore Condition=" '$(CBTModuleImportsBefore)' == '' ">%24(CBTLocalBuildExtensionsPath)\%24(MSBuildThisFile)</CBTModuleImportsBefore> |
| 49 | + <CBTModuleImportsAfter Condition=" '$(CBTModuleImportsAfter)' == '' "></CBTModuleImportsAfter> |
| 50 | + |
| 51 | + <CBTNuGetBinDir Condition=" '$(CBTNuGetBinDir)' == '' ">$(CBTIntermediateOutputPath)\NuGet</CBTNuGetBinDir> |
| 52 | + <CBTNuGetDownloaderAssemblyPath Condition=" '$(CBTNuGetDownloaderAssemblyPath)' == '' ">$(CBTCoreAssemblyPath)</CBTNuGetDownloaderAssemblyPath> |
| 53 | + <CBTNuGetDownloaderClassName Condition=" '$(CBTNuGetDownloaderClassName)' == '' ">CBT.Core.Internal.DefaultNuGetDownloader</CBTNuGetDownloaderClassName> |
| 54 | + <CBTModuleRestoreTaskName Condition=" '$(CBTModuleRestoreTaskName)' == '' ">CBT.Core.Tasks.RestoreModules</CBTModuleRestoreTaskName> |
| 55 | + <CBTModuleRestoreCommand Condition=" '$(CBTModuleRestoreCommand)' == '' ">$(CBTNuGetBinDir)\NuGet.exe</CBTModuleRestoreCommand> |
| 56 | + <CBTModuleRestoreCommandArguments Condition=" '$(CBTModuleRestoreCommandArguments)' == '' ">restore "$(CBTModulePackageConfigPath)" -NonInteractive</CBTModuleRestoreCommandArguments> |
| 57 | + <CBTModuleRestoreCommandArguments Condition=" '$(CBTModuleRestoreCommandAdditionalArguments)' != '' ">$(CBTModuleRestoreCommandArguments) $(CBTModuleRestoreCommandAdditionalArguments)</CBTModuleRestoreCommandArguments> |
| 58 | + |
| 59 | + <!-- Do not restore CBT modules when NuGet is evaluating CBTModules.proj. --> |
| 60 | + <RestoreCBTModules Condition=" $(RestoreGraphProjectInput.Contains($(CBTModulePackageConfigPath))) ">false</RestoreCBTModules> |
| 61 | + <!-- |
| 62 | + Evaluating this property loads CBT.Core.dll as a byte[] and stores the result in the AppDomain via SetData(). This is the only way we could find to load an assembly from bytes and be able to access it in a later call. |
| 63 | + Normally when assemblies are loaded with this context, other calls can't reuse the loaded assembly. Since the Assembly object is stored in the data of the AppDomain, subsequent calls can access via the GetData() method. |
| 64 | + The condition on this property also ensures that the Assembly is only loaded once per AppDomain and since property evaluation is single threaded we don't have to worry about synchronization. Another piece of this |
| 65 | + property is that the the SetData() method returns void so immediately after SetData() we call GetData() which returns the Assembly and the property evaluates to something like: |
| 66 | + "CBT.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" |
| 67 | + |
| 68 | + If the CBTCoreAssemblyName property has a value then we know we were able to successfully load the assembly. |
| 69 | + |
| 70 | + The most complicated part of this call is how to get an object[] to pass to the ReadAllBytes() method. MSBuild coerces the arguments to a method but creating a populated object[] with one call is not possible. By calling |
| 71 | + System.IO.Directory.GetFiles(), we are returned a string[] which MSBuild coerces to an object[] to ReadAllBytes(). |
| 72 | + --> |
| 73 | + <CBTCoreAssemblyName Condition=" Exists('$(CBTCoreAssemblyPath)') And '$(CBTCoreAssemblyPath.GetType().Assembly.GetType(`System.AppDomain`).GetProperty(`CurrentDomain`).GetValue(null).GetData(`CBT_CORE_ASSEMBLY`))' == '' ">$(CBTCoreAssemblyPath.GetType().Assembly.GetType('System.AppDomain').GetProperty('CurrentDomain').GetValue(null).SetData('CBT_CORE_ASSEMBLY', $(CBTCoreAssemblyPath.GetType().Assembly.GetType('System.AppDomain').GetProperty('CurrentDomain').GetValue(null).Load($(CBTCoreAssemblyPath.GetType().Assembly.GetType('System.IO.File').GetMethod('ReadAllBytes').Invoke(null, $([System.IO.Directory]::GetFiles($([System.IO.Path]::GetDirectoryName($(CBTCoreAssemblyPath))), $([System.IO.Path]::GetFileName($(CBTCoreAssemblyPath)))))))))))</CBTCoreAssemblyName> |
| 74 | + <CBTCoreAssemblyName>$(CBTCoreAssemblyPath.GetType().Assembly.GetType('System.AppDomain').GetProperty('CurrentDomain').GetValue(null).GetData('CBT_CORE_ASSEMBLY'))</CBTCoreAssemblyName> |
| 75 | + <CBTModulesRestored Condition=" '$(RestoreCBTModules)' != 'false' And '$(BuildingInsideVisualStudio)' != 'true' And '$(CBTModulesRestored)' != 'true' And '$(CBTCoreAssemblyName)' != '' ">$(CBTCoreAssemblyPath.GetType().Assembly.GetType('System.AppDomain').GetProperty('CurrentDomain').GetValue(null).GetData('CBT_CORE_ASSEMBLY').CreateInstance($(CBTModuleRestoreTaskName)).Execute($(CBTModuleImportsAfter.Split(';')), $(CBTModuleImportsBefore.Split(';')), $(CBTModuleExtensionsPath), $(CBTModulePropertiesFile), $(CBTNuGetDownloaderAssemblyPath), $(CBTNuGetDownloaderClassName), '$(CBTNuGetDownloaderArguments)', $(CBTModuleRestoreInputs.Split(';')), $(CBTModulePackageConfigPath), $(CBTModuleRestoreCommand), $(CBTModuleRestoreCommandArguments), $(MSBuildProjectFullPath), $(MSBuildBinPath)))</CBTModulesRestored> |
| 76 | + |
| 77 | + </PropertyGroup> |
| 78 | + |
| 79 | + <ItemGroup> |
| 80 | + <CBTParseError Condition=" '$(EnlistmentRoot)' == '' " Include="The 'EnlistmentRoot' property must be set. Please ensure it is declared in a properties file before CBT Core is imported."> |
| 81 | + <Code>CBT1000</Code> |
| 82 | + </CBTParseError> |
| 83 | + <CBTParseError Condition=" '$(CBTModulesRestored)' == 'false' " Include="Modules were not restored and the build cannot continue. Refer to other errors for more information."> |
| 84 | + <Code>CBT1001</Code> |
| 85 | + </CBTParseError> |
| 86 | + <CBTParseError Condition=" '$(CBTModulePackageConfigPath)' == '' " Include="The CBT module configuration file packages.config or CBTModules.proj was not found under $(CBTLocalPath) or $(CBTLocalPath)\CBTModules. Please add a CBT module package configuration file or set the property 'CBTModulePackageConfigPath' to your custom location."> |
| 87 | + <Code>CBT1002</Code> |
| 88 | + </CBTParseError> |
| 89 | + </ItemGroup> |
| 90 | + |
| 91 | + <Import Project="$(CBTModulePropertiesFile)" Condition=" ('$(CBTModulesRestored)' == 'true' Or '$(BuildingInsideVisualStudio)' == 'true') And Exists('$(CBTModulePropertiesFile)') "/> |
| 92 | + |
| 93 | + <UsingTask TaskName="RestoreModules" AssemblyFile="$(CBTCoreAssemblyPath)" /> |
| 94 | + <UsingTask TaskName="WriteModuleRestoreInfo" AssemblyFile="$(CBTCoreAssemblyPath)" /> |
| 95 | + |
| 96 | + <Target Name="ShowCBTParseErrors" Condition=" '@(CBTParseError)' != '' "> |
| 97 | + <Error Text="%(CBTParseError.Identity)" Code="%(CBTParseError.Code)" /> |
| 98 | + </Target> |
| 99 | + |
| 100 | + <Target Name="RestoreCBTModules" |
| 101 | + Condition=" '$(RestoreCBTModules)' != 'false' And '$(CBTModulesRestored)' != 'true' " |
| 102 | + Inputs="$(CBTModuleRestoreInputs)" |
| 103 | + Outputs="$([MSBuild]::ValueOrDefault($(CBTModulePropertiesFile), 'null'))"> |
| 104 | + |
| 105 | + <RestoreModules |
| 106 | + AfterImports="$(CBTModuleImportsAfter.Split(';'))" |
| 107 | + BeforeImports="$(CBTModuleImportsBefore.Split(';'))" |
| 108 | + ExtensionsPath="$(CBTModuleExtensionsPath)" |
| 109 | + ImportsFile="$(CBTModulePropertiesFile)" |
| 110 | + MSBuildBinPath="$(MSBuildBinPath)" |
| 111 | + NuGetDownloaderAssemblyPath="$(CBTNuGetDownloaderAssemblyPath)" |
| 112 | + NuGetDownloaderClassName="$(CBTNuGetDownloaderClassName)" |
| 113 | + NuGetDownloaderArguments="$(CBTNuGetDownloaderArguments)" |
| 114 | + PackageConfig="$(CBTModulePackageConfigPath)" |
| 115 | + ProjectFullPath="$(MSBuildProjectFullPath)" |
| 116 | + RestoreCommand="$(CBTModuleRestoreCommand)" |
| 117 | + RestoreCommandArguments="$(CBTModuleRestoreCommandArguments)" |
| 118 | + /> |
| 119 | + |
| 120 | + <PropertyGroup> |
| 121 | + <CBTModulesRestored Condition=" '$(CBTModulesRestored)' != 'true' ">true</CBTModulesRestored> |
| 122 | + </PropertyGroup> |
| 123 | + |
| 124 | + <MSBuild Projects="$(MSBuildProjectFullPath)" |
| 125 | + Targets="CBTDesignTimeBuild" |
| 126 | + Properties="DesignTimeBuild=$(DesignTimeBuild);BuildingProject=$(BuildingProject);BuildingInsideVisualStudio=$(BuildingInsideVisualStudio);CBTModulesRestored=$(CBTModulesRestored)" |
| 127 | + Condition=" '$(CBTModulesRestored)' == 'true' And '$(BuildingInsideVisualStudio)' == 'true' " |
| 128 | + /> |
| 129 | + |
| 130 | + </Target> |
| 131 | + |
| 132 | + <!-- _GenerateRestoreProjectSpec is a from the nuget.targets new to NuGet 4.x. --> |
| 133 | + <Target Name="GenerateModuleRestoreInfo" AfterTargets="_GenerateRestoreProjectSpec" Condition=" '$(RestoreOutputAbsolutePath)' != '' And '$(MSBuildProjectFullPath)' == '$(CBTModulePackageConfigPath)' " > |
| 134 | + <ItemGroup> |
| 135 | + <CBTModuleRestoreInfo Remove="@(CBTModuleRestoreInfo)"/> |
| 136 | + <CBTModuleRestoreInfo Include="ProjectJsonPath"> |
| 137 | + <value>$(_CurrentProjectJsonPath)</value> |
| 138 | + </CBTModuleRestoreInfo> |
| 139 | + <CBTModuleRestoreInfo Include="RestoreProjectStyle"> |
| 140 | + <value>$(RestoreProjectStyle)</value> |
| 141 | + <value Condition=" '$(RestoreProjectStyle)' == '' " >$(NuGetProjectStyle)</value> |
| 142 | + </CBTModuleRestoreInfo> |
| 143 | + <CBTModuleRestoreInfo Include="RestoreOutputAbsolutePath"> |
| 144 | + <value>$(RestoreOutputAbsolutePath)</value> |
| 145 | + </CBTModuleRestoreInfo> |
| 146 | + <CBTModuleRestoreInfo Include="PackageReference"> |
| 147 | + <id>%(PackageReference.Identity)</id> |
| 148 | + <version>%(PackageReference.Version)</version> |
| 149 | + </CBTModuleRestoreInfo> |
| 150 | + </ItemGroup> |
| 151 | + <WriteModuleRestoreInfo File="$(CBTModuleRestoreInfoFile)" Input="@(CBTModuleRestoreInfo)" /> |
| 152 | + </Target> |
| 153 | + |
| 154 | + <Target Name="CBTDesignTimeBuild" DependsOnTargets="$(CBTDesignTimeBuildDependsOn)" /> |
| 155 | + |
| 156 | + <Import Project="$(CBTLocalBuildExtensionsPath)\After.$(MSBuildThisFile)" Condition=" '$(CBTLocalBuildExtensionsPath)' != '' And Exists('$(CBTLocalBuildExtensionsPath)\After.$(MSBuildThisFile)') " /> |
| 157 | + |
| 158 | +</Project> |
0 commit comments