Settings.targets 17.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<Project DefaultTargets="Build" InitialTargets="RestoreToolsetCheck" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="OutDir;Configuration">

  <PropertyGroup>
    <ProjectDir>$(MSBuildThisFileDirectory)..\..\</ProjectDir>
    <NuGetToolPath Condition="">$(ProjectDir)nuget.exe</NuGetToolPath>
    <ToolsetPackagesDir>$(ProjectDir)build\ToolsetPackages\</ToolsetPackagesDir>
    <ToolsetPackagesSemaphore>$(ToolsetPackagesDir)toolsetpackages.semaphore</ToolsetPackagesSemaphore>
    <NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == ''">$(NUGET_PACKAGES)</NuGetPackageRoot> <!-- Respect environment variable if set -->
    <NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' and
                                 '$(OS)' == 'Windows_NT'">$(UserProfile)\.nuget\packages</NuGetPackageRoot>
    <NuGetPackageRoot Condition="'$(NuGetPackageRoot)' == '' and
A
Andy Gocke 已提交
12
                                 '$(OS)' != 'Windows_NT'">$(HOME)\.nuget\packages</NuGetPackageRoot>
13 14 15 16 17 18 19 20 21 22 23

    <!-- 
        $(OS) is only specific enough for windows builds.  For non-windows builds the identifier
        is specified on the command line of MSBuild
    -->
    <BaseNuGetRuntimeIdentifier Condition="'$(OS)' == 'Windows_NT'">win7</BaseNuGetRuntimeIdentifier>
  </PropertyGroup>

  <!-- Import the global NuGet packages -->
  <PropertyGroup>
    <ToolsetCompilerPackageName>Microsoft.Net.Compilers</ToolsetCompilerPackageName>
24
    <ToolsetCompilerPackageVersion>1.3.2</ToolsetCompilerPackageVersion>
25 26
    <RoslynDiagnosticsNugetPackageVersion>1.2.0-beta2</RoslynDiagnosticsNugetPackageVersion>
    <RoslynDiagnosticsPropsFilePath>$(NuGetPackageRoot)\Microsoft.Net.RoslynDiagnostics\$(RoslynDiagnosticsNugetPackageVersion)\build\Microsoft.Net.RoslynDiagnostics.props</RoslynDiagnosticsPropsFilePath>
27
    <RoslynBuildUtilFilePath>$(NuGetPackageRoot)\Roslyn.Build.Util\0.9.4-portable\lib\dotnet\Roslyn.MSBuild.Util.dll</RoslynBuildUtilFilePath>
28 29 30
    <AdditionalFileItemNames>$(AdditionalFileItemNames);PublicAPI</AdditionalFileItemNames>
  </PropertyGroup>

31 32 33 34 35 36
  <!-- Workaround until we move to Microsoft.Net.Compilers.nupkg with this fix: https://github.com/dotnet/roslyn/commit/05c12ebfcdd08a02dbceded5327a8da7a7df23be:
       Use the Microsoft.Net.Compilers.props file with the fix checked into the repo instead of the one that comes along with the nuget package: $(NuGetPackageRoot)\Microsoft.Net.Compilers\$(ToolsetCompilerPackageVersion)\build\Microsoft.Net.Compilers.props -->
  <PropertyGroup>
    <ToolsetCompilerPropsFilePath>$(MSBuildThisFileDirectory)Microsoft.Net.Compilers.props</ToolsetCompilerPropsFilePath>
  </PropertyGroup>

37 38 39 40 41
  <!-- 
    Roslyn uses the WriteCodeFragment task to output generated assembly attributes.  In MSBuild 14.0 update 1 this task 
    produces non-deterministic output.  This is fixed in update 2 but until that is released we use a hand patched
    version of the Task that is deterministic.  

J
Cleanup  
Jared Parsons 已提交
42 43
    MSBuild bug: https://github.com/Microsoft/msbuild/issues/408
    Bug tracking removing this: https://github.com/dotnet/roslyn/issues/8421
44
  -->
45
  <UsingTask TaskName="Roslyn.MSBuild.Util.WriteCodeFragmentEx"
A
Andy Gocke 已提交
46
             AssemblyFile="$(RoslynBuildUtilFilePath)" />
47

48 49
  <Target Name="RestoreToolsetCheck"
      Condition="'$(BuildingProject)' == 'true'">
L
Llewellyn Pritchard 已提交
50
      <Error Text="Toolset packages have not been restored, run Restore.cmd before building"
51 52 53 54 55 56 57 58
             Condition="!Exists('$(ToolsetCompilerPropsFilePath)')" />
  </Target>

  <!-- Prevent vsix manifests from being copied to the shared output directory, makes build more deterministic -->
  <PropertyGroup>
    <CopyVsixManifestToOutput>false</CopyVsixManifestToOutput>
  </PropertyGroup>

59 60 61 62 63
  <!-- Point to the reference assemblies on unix -->
  <PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
      <TargetFrameworkRootPath>$(MSBuildBinPath)\reference-assemblies\Framework</TargetFrameworkRootPath>
  </PropertyGroup>

64 65 66 67 68 69 70 71
  <!-- This file is imported by all projects at the beginning of the project files -->
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
          Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props') AND '$(MSBuildProjectExtension)' != '.vcxproj'" />

  <!-- NuGet props aren't imported by default on *nix so we do that here -->
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\NuGet\Microsoft.NuGet.props"
          Condition="'$(OS)' != 'Windows_NT'" />

A
Andy Gocke 已提交
72 73 74 75 76
  <!-- The /publicsign argument is required for the compiler, but the current MSBuild
       build task can't be redirected and even if it could the new build task is not
       built against the xplat MSBuild references so it can't be loaded properly. Providing
       a response file works around the problem by directly adding the public sign argument
       to all unix compilations. This shouldn't present a problem as it's impossible to
A
Andy Gocke 已提交
77
       fully sign on unix at the moment anyway. Tracked by #7756. -->
A
Andy Gocke 已提交
78
  <PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
79
      <CompilerResponseFile>$(MSBuildThisFileDirectory)..\unix\extra_unix_args.rsp</CompilerResponseFile>
A
Andy Gocke 已提交
80 81
  </PropertyGroup>

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
  </PropertyGroup>

  <PropertyGroup>
    <VisualStudioReferenceMajorVersion Condition="'$(VisualStudioReferenceMajorVersion)' == ''">$(VisualStudioVersion.Substring(0, $(VisualStudioVersion.IndexOf('.'))))</VisualStudioReferenceMajorVersion>
    <VisualStudioReferenceAssemblyVersion Condition="'$(VisualStudioReferenceAssemblyVersion)' == ''">$(VisualStudioReferenceMajorVersion).0.0.0</VisualStudioReferenceAssemblyVersion>
    <VisualStudioCodename>Dev$(VisualStudioReferenceMajorVersion)</VisualStudioCodename>

    <MinimumVisualStudioVersion>$(VisualStudioVersion)</MinimumVisualStudioVersion>

    <VSLToolsPath Condition="'$(VSLToolsPath)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..'))</VSLToolsPath>
    <VSLTargetsPath Condition="'$(VSLTargetsPath)' == ''">$(MSBuildThisFileDirectory)</VSLTargetsPath>

    <Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>

    <SignAssembly Condition="'$(SignAssembly)' == ''">true</SignAssembly>

    <UseRoslynAnalyzers Condition="'$(UseRoslynAnalyzers)' == ''">true</UseRoslynAnalyzers>

102
    <Deterministic>True</Deterministic>
103 104 105 106

    <!-- Only portable PDBs are supported xplat -->
    <DebugType Condition="'$(OS)' != 'Windows_NT'">portable</DebugType>
    <DebugType Condition="'$(OS)' == 'Windows_NT'">pdbonly</DebugType>
107 108
  </PropertyGroup>

T
Tanner Gooding 已提交
109 110 111 112 113 114 115 116 117
  <PropertyGroup Condition="'$(VSCOMNTOOLS)' == ''">
    <VSCOMNTOOLS>$([System.Environment]::ExpandEnvironmentVariables("%VS$(VisualStudioReferenceMajorVersion)0COMNTOOLS%"))</VSCOMNTOOLS>
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(DevEnvDir)' == ''">
    <DevEnvDir>$(VSCOMNTOOLS)\..\IDE</DevEnvDir>
    <DevEnvDir>$([System.IO.Path]::GetFullPath('$(DevEnvDir)'))</DevEnvDir>
  </PropertyGroup>
  
118 119 120 121 122 123 124 125 126 127 128 129 130
  <Choose>
    <When Condition="'$(VisualStudioVersion)' == '12.0'">
      <PropertyGroup>
        <MSBuildAssemblyNameFragment>v12.0</MSBuildAssemblyNameFragment>
      </PropertyGroup>
    </When>

    <Otherwise>
      <PropertyGroup>
        <MSBuildAssemblyNameFragment>Core</MSBuildAssemblyNameFragment>
      </PropertyGroup>
    </Otherwise>
  </Choose>
131 132 133 134 135
  
  <!-- This is a really hacky way to detect whether we are on a legacy or a willow based VS install.
       Basically, we check for a registry key that will only exist in legacy VS installs, and assume
       we are a willow based installation if our VSVersion is 15.0 and the registry key doesn't exist. -->
  <PropertyGroup>
136 137
    <IsVSBeforeDev15Preview4 Condition="'$(OS)' == 'Windows_NT' AND '$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\15.0@InstallDir)' != ''">true</IsVSBeforeDev15Preview4>
    <IsVSBeforeDev15Preview4 Condition="'$(OS)' == 'Windows_NT' AND '$(registry:HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\VisualStudio\15.0@InstallDir)' != ''">true</IsVSBeforeDev15Preview4>
138 139
    <IsVSBeforeDev15Preview4 Condition="'$(IsVSBeforeDev15Preview4)' == 'true' AND Exists('$(MSBuildBinPath)\..\..\..\Common7\IDE\devenv.isolation.ini')">false</IsVSBeforeDev15Preview4>
    <IsVSBeforeDev15Preview4 Condition="'$(IsVSBeforeDev15Preview4)' == 'true' AND Exists('$(MSBuildBinPath)\..\..\..\..\Common7\IDE\devenv.isolation.ini')">false</IsVSBeforeDev15Preview4>
140
  </PropertyGroup>
141

142
  <Choose>
143 144 145 146 147 148 149 150 151 152 153 154 155 156
    <When Condition="'$(VisualStudioVersion)' == '15.0'">
      <Choose>
        <When Condition="'$(IsVSBeforeDev15Preview4)' == 'true'">
          <PropertyGroup>
            <VisualStudioBuildToolsNuGetPackagePath>$(NuGetPackageRoot)\Microsoft.VSSDK.BuildTools\15.0.25201-dev15preview2</VisualStudioBuildToolsNuGetPackagePath>
          </PropertyGroup>
        </When>

        <Otherwise>
          <PropertyGroup>
            <VisualStudioBuildToolsNuGetPackagePath>$(NuGetPackageRoot)\Microsoft.VSSDK.BuildTools\15.0.25604-Preview4</VisualStudioBuildToolsNuGetPackagePath>
          </PropertyGroup>
        </Otherwise>
      </Choose>
157 158 159 160
    </When>

    <Otherwise>
      <PropertyGroup>
161
        <VisualStudioBuildToolsNuGetPackagePath>$(NuGetPackageRoot)\Microsoft.VSSDK.BuildTools\14.3.25420</VisualStudioBuildToolsNuGetPackagePath>
162 163 164 165 166 167
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <Import Project="$(VisualStudioBuildToolsNuGetPackagePath)\build\Microsoft.VsSDK.BuildTools.props" Condition="'$(OS)' == 'Windows_NT'" />

168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
  <!-- Build reliability -->
  <PropertyGroup>
    <OverwriteReadOnlyFiles Condition="'$(OverwriteReadOnlyFiles)' == ''">true</OverwriteReadOnlyFiles>
  </PropertyGroup>

  <!-- Project language -->
  <PropertyGroup Condition="'$(ProjectLanguage)' == ''">
    <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.csproj' OR '$(Language)' == 'C#'">CSharp</ProjectLanguage>
    <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.vbproj' OR '$(Language)' == 'VB'">VB</ProjectLanguage>
    <ProjectLanguage Condition="'$(MSBuildProjectExtension)' == '.vcxproj' OR '$(Language)' == 'C++'">C++</ProjectLanguage>
  </PropertyGroup>

  <PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
    <!-- Use the compiler server -->
    <UseSharedCompilation>true</UseSharedCompilation>
  </PropertyGroup>

  <!-- Import the props files from the toolset NuGet packages if we're not in a bootstrap build -->
  <ImportGroup Label="GlobalNuGets" Condition="'$(BootstrapBuildPath)' == ''">
    <Import Project="$(ToolsetCompilerPropsFilePath)"
188
            Condition="Exists('$(ToolsetCompilerPropsFilePath)') And '$(OS)' == 'Windows_NT'" />
189 190 191 192 193 194 195
  </ImportGroup>

  <ImportGroup>
    <Import Project="$(RoslynDiagnosticsPropsFilePath)"
            Condition="Exists('$(RoslynDiagnosticsPropsFilePath)') And ('$(UseRoslynAnalyzers)' == 'true')" />
  </ImportGroup>

A
Andy Gocke 已提交
196 197
  <!-- Otherwise, use the task from the bootstrap location. This is necessary
       to support new properties on the build task. -->
198 199 200 201 202 203 204
  <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Csc"
             AssemblyFile="$(BootstrapBuildPath)\Microsoft.Build.Tasks.CodeAnalysis.dll"
             Condition="'$(BootstrapBuildPath)' != ''" />
  <UsingTask TaskName="Microsoft.CodeAnalysis.BuildTasks.Vbc"
             AssemblyFile="$(BootstrapBuildPath)\Microsoft.Build.Tasks.CodeAnalysis.dll"
             Condition="'$(BootstrapBuildPath)' != ''" />

205
  <PropertyGroup Condition="'$(BootstrapBuildPath)' != ''">
206 207 208
    <UseSharedCompilation>true</UseSharedCompilation>
    <CSharpCoreTargetsPath>$(BootstrapBuildPath)\Microsoft.CSharp.Core.targets</CSharpCoreTargetsPath>
    <VisualBasicCoreTargetsPath>$(BootstrapBuildPath)\Microsoft.VisualBasic.Core.targets</VisualBasicCoreTargetsPath>
209 210
  </PropertyGroup>

211

212 213 214 215 216
  <!-- Common project settings -->
  <PropertyGroup>
    <DeployToSamplesSubfolder Condition="'$(DeployToSamplesSubfolder)' == ''">false</DeployToSamplesSubfolder>
    <FileAlignment>512</FileAlignment>
    <HighEntropyVA>true</HighEntropyVA>
217
    <Features>strict</Features>
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
  </PropertyGroup>

  <!--
    If TargetNetFX20 is true the project targets Framework 2.0 reference assemblies provided by Microsoft.NetFX20 nuget package.
    Use the latest Framework toolset to build, but set msbuild properties below
    so to avoid 4.5 specific artifacts to be added to the compilation (references, attributes).
  -->
  <PropertyGroup Condition="'$(TargetNetFX20)' == 'true'">
    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
    <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
    <NoStdLib>true</NoStdLib>
    <FrameworkPathOverride>$(NuGetPackageRoot)\Microsoft.NetFX20\1.0.3\lib\net20</FrameworkPathOverride>
    <NuGetTargetMoniker>.NETFramework,Version=v2.0</NuGetTargetMoniker>
  </PropertyGroup>

  <ItemGroup Condition="'$(ProjectLanguage)' == 'CSharp' AND '$(TargetNetFX20)' == 'true'">
    <_ExplicitReference Include="$(FrameworkPathOverride)\mscorlib.dll" />
  </ItemGroup>

  <PropertyGroup>
    <OutDir Condition="'$(OutDir)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\Binaries\$(Configuration)'))\</OutDir>
    <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\..\Binaries\Obj\$(MSBuildProjectName)'))\</BaseIntermediateOutputPath>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Capture the root, so we'll always have it even if we're building to a sub-folder -->
    <VSLOutDir>$(OutDir)</VSLOutDir>
  </PropertyGroup>

247 248 249 250
  <PropertyGroup>
      <CompilerGeneratorToolsDir>$(OutDir)CompilerGeneratorTools\</CompilerGeneratorToolsDir>
  </PropertyGroup>

251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
  <PropertyGroup Condition="'$(DeployToSamplesSubfolder)' == 'true'">
    <OutDir>$(OutDir)\Samples\$(MSBuildProjectName)</OutDir>
  </PropertyGroup>

  <PropertyGroup>
  <!-- Disable AppX packaging for the Roslyn source. Not setting this to false has the side effect
       that any builds of portable projects end up in a sub folder of $(OutDir). Search for this flag in
       Microsoft.Common.CurrentVersion.targets to see how it is consumed -->
    <WindowsAppContainer>false</WindowsAppContainer>
  </PropertyGroup>

  <Choose>
    <!-- VB specific settings -->
    <When Condition="'$(ProjectLanguage)' == 'VB'">
      <PropertyGroup>
        <MyType>Empty</MyType>
        <OptionCompare>Binary</OptionCompare>
        <OptionExplicit>On</OptionExplicit>
        <OptionInfer>On</OptionInfer>
        <OptionStrict>On</OptionStrict>
        <RootNamespace></RootNamespace>
        <VBRuntime>Embed</VBRuntime>
      </PropertyGroup>
      <ItemGroup>
        <Import Include="Microsoft.VisualBasic" />
        <Import Include="System" />
        <Import Include="System.Collections" />
        <Import Include="System.Collections.Generic" />
        <Import Include="System.Diagnostics" />
      </ItemGroup>
      <ItemGroup Condition="'$(TargetNetFX20)' != 'true'">
        <Import Include="System.Linq" />
      </ItemGroup>
      <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
        <DebugSymbols>true</DebugSymbols>
        <DefineDebug>true</DefineDebug>
        <DefineTrace>true</DefineTrace>
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <DefineTrace>true</DefineTrace>
        <Optimize>true</Optimize>
      </PropertyGroup>
    </When>

    <!-- C# specific settings -->
    <When Condition="'$(ProjectLanguage)' == 'CSharp'">
      <PropertyGroup>
        <WarningLevel>4</WarningLevel>
        <ErrorReport>prompt</ErrorReport>

        <!-- Suppress the following warnings by default for C# projects
                1591: So far we've chosen to implicitly implement interfaces and as a consequence
                      the methods are public.  We don't want to duplicate documentation for them
                      and hence suppress this warning until we get closer to release and a more
                      thorough documentation story
        -->
307
        <NoWarn>$(NoWarn);1591</NoWarn>
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
        <DebugSymbols>true</DebugSymbols>
        <DefineConstants>DEBUG;TRACE</DefineConstants>
      </PropertyGroup>
      <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <DefineConstants>TRACE</DefineConstants>
        <Optimize>true</Optimize>
      </PropertyGroup>
    </When>

    <!-- C++ specific settings -->
    <When Condition="'$(ProjectLanguage)' == 'C++'">
      <PropertyGroup>
        <!-- Put intermediate outputs in the same place as managed projects for sanity -->
        <IntDir>$(ProjectDir)obj\$(Configuration)\</IntDir>

        <!-- We just always want to build with whatever toolset matches the VS you're building with -->
        <PlatformToolset>v$(VisualStudioReferenceMajorVersion)0</PlatformToolset>
      </PropertyGroup>
    </When>
  </Choose>

  <PropertyGroup>
    <CopyVSReferencesToOutput>True</CopyVSReferencesToOutput>
  </PropertyGroup>
J
Jared Parsons 已提交
334 335 336 337 338 339 340 341 342 343 344 345

  <!-- 
    When running our determinism tests we need to copy the diagnostic file from the intermediate directory 
    to the location of the binary.  This ensures .dll and .dll.key are next to each other to be picked up
    by our test scripts
  -->
  <Target Name="CopyDeterministicBuildDiagnosticFile" Condition="'$(DebugDeterminism)' != ''" AfterTargets="CoreCompile">
    <Copy
        Condition="Exists(@(IntermediateAssembly -> '%(fullpath).key'))"
        SourceFiles="@(IntermediateAssembly -> '%(fullpath).key')"
        DestinationFolder="$(OutDir)" />
  </Target>
346
 </Project>