<commit_before><?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation.  All Rights Reserved.  See License.txt in the project root for license information. -->
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <FSCoreVersion>4.4.1.0</FSCoreVersion>
  </PropertyGroup>

  <Choose>
    <When Condition="'$(Configuration)' == 'Debug' or '$(Configuration)' == 'Release' ">
      <PropertyGroup>
        <SkipSigning>false</SkipSigning><!-- Skip using the ,net toolset to generate signing . -->
        <UseOpenSourceSign>true</UseOpenSourceSign>
      </PropertyGroup>
      <Choose>
        <When Condition="'$(ProjectLanguage)' == 'FSharp'">
          <Choose>
            <!-- Some unit test assemblies must not have strong names since they reference other assemblies that don't have strong names -->
            <!-- These unit test assemblies can't use InternalsVisibleTo into assemblies with strong names. -->
            <When Condition="'$(StrongNames)' == 'false'" >
              <PropertyGroup>
                <SkipSigning>true</SkipSigning>
                <UseOpenSourceSign>false</UseOpenSourceSign>
                <MicroBuildAssemblyVersion Condition="'$(MicroBuildAssemblyVersion)' == ''">$(FSCoreVersion)</MicroBuildAssemblyVersion>
                <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
              </PropertyGroup>
            </When>
            <!-- In the open source "Mono" build we always fully sign the binaries with the public test.snk, apart from FSharp.Core, which gets the MSFT key -->
            <When Condition="'$(MonoPackaging)' == 'true' AND '$(AssemblyName)'!='FSharp.Core'" >
              <PropertyGroup>
                <OtherFlags>$(OtherFlags) --keyfile:"$(FSharpSourcesRoot)\fsharp\test.snk"</OtherFlags>
                <DefineConstants>STRONG_NAME_FSHARP_COMPILER_WITH_TEST_KEY;$(DefineConstants)</DefineConstants>
                <StrongNames>true</StrongNames>
                <MicroBuildAssemblyVersion Condition="'$(MicroBuildAssemblyVersion)' == ''">$(FSCoreVersion)</MicroBuildAssemblyVersion>
                <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
              </PropertyGroup>
            </When>
            <!-- In the Microsoft build we just delay-sign everything with the MSFT key -->
            <!-- We have to do unit test DLLs well because they can see the internals of other strong-named DLLs -->
            <Otherwise>
              <PropertyGroup>
                <OtherFlags Condition="'$(TargetDotnetProfile)' == 'coreclr' or $(BUILD_PUBLICSIGN) != '1'">$(OtherFlags) --delaysign+</OtherFlags>
                <OtherFlags Condition="'$(TargetDotnetProfile)' != 'coreclr' and $(BUILD_PUBLICSIGN) == '1'">$(OtherFlags)  --publicsign+</OtherFlags>
                <OtherFlags>$(OtherFlags) --keyfile:"$(FSharpSourcesRoot)\fsharp\msft.pubkey"</OtherFlags>
                <DefineConstants>STRONG_NAME_AND_DELAY_SIGN_FSHARP_COMPILER_WITH_MSFT_KEY;$(DefineConstants)</DefineConstants>
                <StrongNames>true</StrongNames>
                <MicroBuildAssemblyVersion>$(FSCoreVersion)</MicroBuildAssemblyVersion>
                <!-- certain delivered F# VS assemblies use a specific MicroBuildAssemblyVersion, otherwise use FSCoreVersion -->
                <MicroBuildAssemblyVersion Condition="'$(UseVsMicroBuildAssemblyVersion)' == 'true'">15.4.1.0</MicroBuildAssemblyVersion>
                <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
              </PropertyGroup>
            </Otherwise>
          </Choose>
        </When>
        <Otherwise>
          <!-- Not F# code -->
          <PropertyGroup>
            <SignAssembly>true</SignAssembly>
            <AssemblyOriginatorKeyFile>$(FSharpSourcesRoot)\fsharp\msft.pubkey</AssemblyOriginatorKeyFile>
            <DefineConstants>STRONG_NAME_AND_DELAY_SIGN_FSHARP_COMPILER_WITH_MSFT_KEY;$(DefineConstants)</DefineConstants>
            <StrongNames>true</StrongNames>
            <DelaySign>true</DelaySign>
            <MicroBuildAssemblyVersion>$(FSCoreVersion)</MicroBuildAssemblyVersion>
            <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
          </PropertyGroup>
        </Otherwise>
      </Choose>
    </When>
    <Otherwise>
      <PropertyGroup Condition="'$(StrongNames)' != 'true'">
        <!-- For the proto build we don't use strong names. -->
        <DefineConstants>NO_STRONG_NAMES;$(DefineConstants)</DefineConstants>
        <MicroBuildAssemblyVersion>$(FSCoreVersion)</MicroBuildAssemblyVersion>
        <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup Condition="'$(UseMicroBuild)' != 'true'">
    <OtherFlags >$(OtherFlags) --version:"$(MicroBuildAssemblyVersion)"</OtherFlags>
  </PropertyGroup>

  <PropertyGroup Condition="'$(UseSourceLink)' == 'true'">
    <SourceLink>$(IntermediateOutputPath)source_link.json</SourceLink>
  </PropertyGroup>

  <PropertyGroup Condition="'$(StrongNames)' != 'true'">
    <DefineConstants>NO_STRONG_NAMES;$(DefineConstants)</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(MonoPackaging)' != 'true'">
    <DefineConstants>MSBUILD_AT_LEAST_14;$(DefineConstants)</DefineConstants>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Disable uwa toolchain nuget package resolve logic. -->
    <NuGetTargets  Condition="'$(NuGetTargets)' == ''">false</NuGetTargets>
  </PropertyGroup>  

  <PropertyGroup>
    <NugetLocalPackagesDir>$(FSharpSourcesRoot)\..\packages</NugetLocalPackagesDir>
    <NUnitVersion>3.5.0</NUnitVersion>
    <NUnitFullVersion>3.5.0.0</NUnitFullVersion>
    <NUnitLibDir>$(FSharpSourcesRoot)\..\packages\NUnit.$(NUnitVersion)\lib\net45</NUnitLibDir>
    <NUnitToolsLibDir>$(FSharpSourcesRoot)\..\packages\NUnit.ConsoleRunner\$(NUnitVersion)\tools\</NUnitToolsLibDir>
    <FsCheckVersion>2.6.2</FsCheckVersion>
    <FsCheckFullVersion>2.6.2.0</FsCheckFullVersion>
    <FsCheckLibDir>$(FSharpSourcesRoot)\..\packages\FsCheck.$(FsCheckVersion)\lib\</FsCheckLibDir>
  </PropertyGroup>

  <Import Project="FSharpSource.Profiles.targets" />

  <PropertyGroup Condition="'$(TargetDotnetProfile)'=='net40'">
    <TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v4.5</TargetFrameworkVersion>
    <TargetFrameworkProfile></TargetFrameworkProfile>
    <!-- MSbuild works out the assembly references -->
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetDotnetProfile)'=='coreclr'">
    <TargetProfile>netcore</TargetProfile>
    <TargetFrameworkProfile></TargetFrameworkProfile>                                   <!-- We are currently directly referencing corefx assemblies, so profile7 is not really true -->
    <TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v5.0</TargetFrameworkVersion>
    <ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework>            <!-- To stop msbuild being helpful and referencing the dlls for the profile -->
    <NuGetTargetMoniker>.NETStandard,Version=v1.6</NuGetTargetMoniker>
    <PortableNuGetMode>true</PortableNuGetMode>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(TargetDotnetProfile)'=='coreclr' AND '$(DOTNET_PUBLISH_TEST)'=='true' ">
    <OutputPath>bin\$(Configuration)\netcoreapp1.0</OutputPath>
    <CustomOutputPath>true</CustomOutputPath>
    <DOTNET_PUBLISH>true</DOTNET_PUBLISH>
    <DOTNET_PUBLISH_PLATFORM>win7-x64</DOTNET_PUBLISH_PLATFORM>
    <DOTNET_PUBLISH_PATH>$(FSharpSourcesRoot)\..\tests\testbin\$(Configuration)\coreclr\$(AssemblyName)</DOTNET_PUBLISH_PATH>
    <OutputType>Exe</OutputType>
    <TargetExt>.dll</TargetExt>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(TargetDotnetProfile)'=='coreclr' AND '$(DOTNET_PUBLISH_COMPILERS)'=='true' ">
    <DOTNET_PUBLISH_FSC>true</DOTNET_PUBLISH_FSC>
    <DOTNET_PUBLISH_FSC_PATH>$(FSharpSourcesRoot)\..\tests\testbin\$(Configuration)\coreclr\FSC</DOTNET_PUBLISH_FSC_PATH>
    <DOTNET_PUBLISH_FSI>true</DOTNET_PUBLISH_FSI>
    <DOTNET_PUBLISH_FSI_PATH>$(FSharpSourcesRoot)\..\tests\testbin\$(Configuration)\coreclr\FSC</DOTNET_PUBLISH_FSI_PATH>
  </PropertyGroup>

  <!-- If building an FSharp.Core for a back version (Mono Debian source builds only), put it in a qualified directory -->
  <PropertyGroup>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == ''">$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == '3.0'">fsharp30\$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == '3.1'">fsharp31\$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == '4.0'">fsharp40\$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <IntermediateOutputPath>obj\$(TargetFrameworkOutputDirectory)\</IntermediateOutputPath>
  </PropertyGroup>

  <Choose>
    <When Condition="'$(BuildWith)' == 'LKG' AND '$(BUILD_PROTO_WITH_CORECLR_LKG)' == '1'">
      <PropertyGroup >
        <OutputPath>$(FSharpSourcesRoot)\..\$(Configuration)\$(ProtoFlavour)\bin</OutputPath>
        <!-- When using coreclr to bootstrap to proto. We acquire the FSharp.Core LKG, targets LKG, the FSharp.Build LKG from the .NET Framework compiler tools LKG package. -->
        <FSharpNetCoreLkgPath>$(FSharpSourcesRoot)\..\Tools\dotnet20\sdk\2.0.0-preview2-006502\FSharp</FSharpNetCoreLkgPath>
        <FSharpTargetsPath>..\packages\FSharp.Compiler.Tools.4.1.27\tools\Microsoft.FSharp.Targets</FSharpTargetsPath>

        <!-- When using coreclr to bootstrap, the compiler binary comes from the coreclr LKG, invoked using corehost.exe -->
        <FscToolPath>$(FSharpSourcesRoot)\..\Tools\dotnet20</FscToolPath>
        <FscToolExe Condition="'$(OS)' != 'Unix'">dotnet.exe</FscToolExe>
        <FscToolExe Condition="'$(OS)' == 'Unix'">dotnet</FscToolExe>
        <DotnetFscCompilerPath>$(FSharpNetCoreLkgPath)\fsc.exe</DotnetFscCompilerPath>
      </PropertyGroup>
    </When>
    <When Condition="'$(BuildWith)' == 'LKG' AND '$(BUILD_PROTO_WITH_CORECLR_LKG)' != '1'">
       <!-- Use .NET Framework to bootstrap to proto -->
      <PropertyGroup >
        <OutputPath>$(FSharpSourcesRoot)\..\$(Configuration)\$(ProtoFlavour)\bin</OutputPath>
        <FSharpTargetsPath>..\packages\FSharp.Compiler.Tools.4.1.27\tools\Microsoft.FSharp.Targets</FSharpTargetsPath>
      </PropertyGroup>
    </When>
    <When Condition="'$(BuildWith)' == '' AND '$(TargetDotnetProfile)'=='coreclr'">
      <!-- Compiling coreclr with Proto, currently always use a .NET Framework/Mono proto -->
      <PropertyGroup>
        <OutputPath Condition=" '$(CustomOutputPath)' != 'true' ">$(FSharpSourcesRoot)\..\$(Configuration)\$(TargetFrameworkOutputDirectory)\bin</OutputPath>
        <FscToolPath>$(FSharpSourcesRoot)\..\Proto\$(ProtoFlavour)\bin</FscToolPath>
        <FscToolExe>fsc-proto.exe</FscToolExe>
        <FSharpTargetsPath>..\Proto\$(ProtoFlavour)\bin\Microsoft.Portable.FSharp-proto.targets</FSharpTargetsPath>
      </PropertyGroup>
    </When>
    <Otherwise>
      <!-- Compiling net40 with Proto -->
      <PropertyGroup>
        <OutputPath Condition=" '$(CustomOutputPath)' != 'true' ">$(FSharpSourcesRoot)\..\$(Configuration)\$(TargetFrameworkOutputDirectory)\bin</OutputPath>
        <FscToolPath>$(FSharpSourcesRoot)\..\Proto\$(ProtoFlavour)\bin</FscToolPath>
        <FscToolExe>fsc-proto.exe</FscToolExe>
        <FSharpTargetsPath>..\Proto\$(ProtoFlavour)\bin\Microsoft.FSharp-proto.targets</FSharpTargetsPath>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup>
    <CompileDependsOn>ValidateBuildTools;$(CompileDependsOn)</CompileDependsOn>
  </PropertyGroup>

  <Target Name="ValidateBuildTools" Condition="'$(ProjectLanguage)' == 'FSharp'" >
    <Message Text="FSharpTargetsPath = $(FSharpTargetsPath)" />
    <Message Text="FSharpSourcesRoot = $(FSharpSourcesRoot)" />
    <Message Text="FscToolPath = $(FscToolPath)" />
    <Message Text="FsiToolPath = $(FsiToolPath)" />
    <Message Text="FsLexToolPath = $(FsLexToolPath)" />
    <Message Text="FsYaccToolPath = $(FsYaccToolPath)" />
    <Message Text="ToolsDir = $(ToolsDir)" />
    <Error Text="Expect $(FSharpTargetsPath) to exist" Condition="'!Exists('$(FSharpTargetsPath)')" />
    <Error Text="Expect $(FSharpNetCoreLkgPath)\fsc.exe to exist when BUILD_PROTO_WITH_CORECLR_LKG==1" Condition="'$(BUILD_PROTO_WITH_CORECLR_LKG)' == 1 AND !Exists('$(FSharpNetCoreLkgPath)\fsc.exe')" />
    <Error Text="Expect $(FscToolPath)\$(FscToolExe) to exist" Condition="!Exists('$(FscToolPath)\$(FscToolExe)')" />
    <Error Text="Expect $(DotnetFscCompilerPath) to exist if non-empty" Condition="'$(DotnetFscCompilerPath)' != '' AND !Exists('$(DotnetFscCompilerPath)')" />
    <Error Text="Expect $(FsiToolPath)\$(FsiToolExe) to exist" Condition="!Exists('$(FsiToolPath)\$(FsiToolExe)')" />
    <Error Text="Expect $(FsLexToolPath)\$(FsLexToolExe) to exist" Condition="!Exists('$(FsLexToolPath)\$(FsLexToolExe)')" />
    <Error Text="Expect $(FsYaccToolPath)\$(FsYaccToolExe) to exist" Condition="!Exists('$(FsYaccToolPath)\$(FsYaccToolExe)')" />
  </Target>

  <Import Condition="'$(ProjectLanguage)' == 'FSharp'" Project="$(FSharpTargetsPath)"/>

  <!-- Hook up .NET Core to enable solution refresh of packages -->
  <PropertyGroup Condition="'$(TargetDotnetProfile)'=='coreclr'">

    <!-- Implicitly needed by packageresolve.targets.  Should file a bug for a better error message here -->
    <PackagesDir>$(NUGET_PACKAGES)</PackagesDir>

    <NuGetToolPath Condition="'$(NuGetToolPath)' == ''">$(FSharpSourcesRoot)\..\.nuget\</NuGetToolPath>
    <NuGetConfigCommandLine>-ConfigFile "$(NuGetConfigFile)"</NuGetConfigCommandLine>
    <NugetRestoreCommand>"$(NuGetToolPath)NuGet.exe install -OutputDirectory "$(PackagesDir)" -Config "$(NuGetToolPath)NuGet.Config"</NugetRestoreCommand>
    <DnuRestoreCommand>"$(NuGetToolPath)NuGet.exe" restore -OutputDirectory "$(PackagesDir)" -Config "$(NuGetToolPath)NuGet.Config"</DnuRestoreCommand>

    <!-- Current version of .NET Core does not support all semantics used in our packages, 
         so we ignore the pre-calculation in the lock file and calculate asset applicability in the build task -->
    <NuGetIngoreLockFile>true</NuGetIngoreLockFile>
  </PropertyGroup>
  <Import  Condition="'$(TargetDotnetProfile)'=='coreclr'" Project="..\Tools\Build.Common.Targets" />

  <PropertyGroup>
    <RootNamespace></RootNamespace>
    <DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
  </PropertyGroup>

  <PropertyGroup>
    <PackageLicenceUrl Condition="'$(PackageLicenceUrl)' == ''">https://github.com/Microsoft/visualfsharp/blob/master/License.txt</PackageLicenceUrl>
    <PackageProjectUrl Condition="'$(PackageProjectUrl)' == ''">https://github.com/Microsoft/visualfsharp</PackageProjectUrl>
    <PackageVersion    Condition="'$(PackageVersion)' == ''"   >$(NuGetPerBuildPreReleaseVersion)</PackageVersion>
    <PackageAuthors    Condition="'$(PackageAuthors)' == ''"   >Microsoft</PackageAuthors>
    <PackageTags       Condition="'$(PackageTags)' == ''"      >Visual F# Compiler FSharp coreclr functional programming</PackageTags>
  </PropertyGroup>

  <!-- This build step copies files to the output folder while replacing build variables in the text of those file. -->
  <PropertyGroup>
    <CompileDependsOn>$(CompileDependsOn);CopyAndSubstituteTextFiles</CompileDependsOn>
  </PropertyGroup>

  <Target
          Name="CopyAndSubstituteTextFiles"
          Inputs="@(CopyAndSubstituteText)"
          Outputs="@(CopyAndSubstituteText->'$(OutDir)%(TargetFilename)')"  >
    <Exec Command="&quot;$([System.IO.Path]::GetFullPath('$(FsiToolPath)\$(FsiToolExe)'))&quot; --exec &quot;$(MSBuildThisFileDirectory)scripts/subst.fsx&quot; --in:&quot;%(CopyAndSubstituteText.FullPath)&quot; --out:&quot;$(OutDir)%(CopyAndSubstituteText.TargetFilename)&quot; --pattern1:&quot;%(CopyAndSubstituteText.Pattern1)&quot; --replacement1:&quot;%(CopyAndSubstituteText.Replacement1)&quot; --pattern2:&quot;%(CopyAndSubstituteText.Pattern2)&quot; --replacement2:&quot;%(CopyAndSubstituteText.Replacement2)&quot; " Condition="'$(OS)' != 'Unix'" />
    <Exec Command="mono $([System.IO.Path]::GetFullPath('$(FsiToolPath)\$(FsiToolExe)')) --exec &quot;$(MSBuildThisFileDirectory)scripts/subst.fsx&quot; --in:&quot;%(CopyAndSubstituteText.FullPath)&quot; --out:&quot;$(OutDir)%(CopyAndSubstituteText.TargetFilename)&quot; --pattern1:&quot;%(CopyAndSubstituteText.Pattern1)&quot; --replacement1:&quot;%(CopyAndSubstituteText.Replacement1)&quot; --pattern2:&quot;%(CopyAndSubstituteText.Pattern2)&quot; --replacement2:&quot;%(CopyAndSubstituteText.Replacement2)&quot; " Condition="'$(OS)' == 'Unix'" />
    <!-- Make sure it will get cleaned  -->
    <CreateItem Include="$(OutDir)%(CopyAndSubstituteText.TargetFilename)">
      <Output TaskParameter="Include" ItemName="FileWrites"/>
    </CreateItem>
  </Target>
  <Import Project="$(FSharpSourcesRoot)\scripts\fssrgen.targets" Condition="'$(Configuration)' == 'Proto'" />
  <Import Project="Microbuild.Settings.targets" Condition="'$(UseMicroBuild)' == 'true'"/>

  <Target Name="dotnetrestore" BeforeTargets="Build" Condition=" '$(TargetDotnetProfile)' == 'coreclr' ">
   <Exec Command="$(MSBuildThisFileDirectory)..\.nuget\nuget.exe restore -PackagesDirectory $(PackagesDir) -Config $(MSBuildThisFileDirectory)..\.nuget\NuGet.Config project.json" />
  </Target>

  <Target Name="dotnetrestore" BeforeTargets="Build" Condition=" '$(DOTNET_PUBLISH)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe restore &#45;&#45;configfile $(MSBuildThisFileDirectory)..\.nuget\NuGet.Config project.json"/>
  </Target>

  <Target Name="dotnetpublish" AfterTargets="Build" Condition=" '$(DOTNET_PUBLISH)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe &#45;&#45;verbose publish &#45;&#45;no-build project.json -r $(DOTNET_PUBLISH_PLATFORM) -c $(Configuration) -o $(DOTNET_PUBLISH_PATH)"/>
  </Target>

  <Target Name="dotnetpublishfsccompiler" AfterTargets="CopyFilesToOutputDirectory" Condition=" '$(DOTNET_PUBLISH_FSC)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe restore DeployCompiler\fsc\project.json"/>
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe &#45;&#45;verbose publish &#45;&#45;no-build DeployCompiler\fsc\project.json -r $(DOTNET_PUBLISH_PLATFORM) -c $(Configuration) -o $(DOTNET_PUBLISH_FSC_PATH)"/>
  </Target>

  <Target Name="dotnetpublishfsicompiler" AfterTargets="CopyFilesToOutputDirectory" Condition=" '$(DOTNET_PUBLISH_FSI)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe restore DeployCompiler\fsi\project.json"/>
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe &#45;&#45;verbose publish &#45;&#45;no-build DeployCompiler\fsi\project.json -r $(DOTNET_PUBLISH_PLATFORM) -c $(Configuration) -o $(DOTNET_PUBLISH_FSI_PATH)"/>
  </Target>

  <Target Name="GenerateSourceLink" BeforeTargets="CoreCompile" Condition="'$(UseSourceLink)' == 'true'">
    <PropertyGroup>
      <SrcRootDirectory>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory.TrimEnd("\"))))</SrcRootDirectory>
      <SourceLinkRoot>$(SrcRootDirectory.Replace("\", "\\"))</SourceLinkRoot>
    </PropertyGroup>

    <Exec Command="git config --get remote.origin.url" ConsoleToMsBuild="true">
      <Output TaskParameter="ConsoleOutput" PropertyName="RemoteUri" />
    </Exec>

    <!-- https://raw.githubusercontent.com/KevinRansom/visualfsharp/98e8c9a2ca09a36ebd024eb424fc050a831053cd/build.cmd  -->
    <Exec Command="git rev-parse HEAD" ConsoleToMsBuild="true" Condition = " '$(TF_BUILD)' != 'True' ">
      <Output TaskParameter="ConsoleOutput" PropertyName="LatestCommit" />
    </Exec>

    <Exec Command="git merge-base --fork-point refs/remotes/visualfsharptools/master HEAD" ConsoleToMsBuild="true" Condition = " '$(TF_BUILD)' == 'True' ">
      <Output TaskParameter="ConsoleOutput" PropertyName="LatestCommit" />
    </Exec>

    <WriteLinesToFile File="$(IntermediateOutputPath)source_link.json" Overwrite="true" Lines='{"documents": { "$(SourceLinkRoot)\\*" : "$(RemoteUri.Replace(".git", "").Replace("github.com", "raw.githubusercontent.com"))/$(LatestCommit)/*" }}' />
  </Target>

    <!-- If BuildVersionFilePath not specified then do nothing  -->
  <Target Name="CleanVersionFile" Condition ="'$(BuildVersionFilePath)' != '' ">
    <PropertyGroup>
        <BuildVersionFileDir>$([System.IO.Path]::GetDirectoryName($(BuildVersionFilePath)))</BuildVersionFileDir>
    </PropertyGroup>
    <RemoveDir Condition="Exists('$(BuildVersionFileDir)')" Directories="$(BuildVersionFileDir)" />
  </Target>

    <!-- If BuildVersionFilePath not specified then do nothing  -->
  <Target Name="CreateOrUpdateBuildVersionFile" Condition ="'$(BuildVersionFilePath)' != '' ">
    <PropertyGroup>
        <BuildVersionFileDir>$([System.IO.Path]::GetDirectoryName($(BuildVersionFilePath)))</BuildVersionFileDir>
        <PackageVersionMajor Condition="'$(PackageVersionMajor)' == ''" >$(NuGetPerBuildPreReleaseVersion)</PackageVersionMajor>
        <PackageVersionMinor Condition="'$(PackageVersionMinor)' != ''" >$([MSBuild]::Add($(PackageVersionMinor), 1))</PackageVersionMinor>
        <PackageVersionMinor Condition="'$(PackageVersionMinor)' == ''" >1</PackageVersionMinor>
    </PropertyGroup>

    <ItemGroup>
      <CurrentVersionLines Include="%3C%3Fxml version=%221.0%22 encoding=%22utf-8%22%3F%3E" />
      <CurrentVersionLines Include="%3C!-- This is a generated file. $(VersionSeedSourceComment) Seed Date is $(VersionSeedDate). --%3E" />
      <CurrentVersionLines Include="%3CProject xmlns=%22http://schemas.microsoft.com/developer/msbuild/2003%22%3E" />
      <CurrentVersionLines Include="%3CPropertyGroup%3E" />
      <CurrentVersionLines Include="%3CPackageVersionMajor Condition=%22%27%24(PackageVersionMajor)%27==%27%27%22%3E$(NuGetPerBuildPreReleaseVersion)%3C/PackageVersionMajor%3E" />
      <CurrentVersionLines Include="%3CPackageVersionMinor Condition=%22%27%24(PackageVersionMinor)%27==%27%27%22%3E$(PackageVersionMinor)%3C/PackageVersionMinor%3E" />
      <CurrentVersionLines Include="%3C/PropertyGroup%3E" />
      <CurrentVersionLines Include="%3C/Project%3E" />
    </ItemGroup>

    <!-- Since by default the file will get dropped at the obj dir, make sure that the dir is created already or else WriteLinesToFile will error. -->
    <MakeDir Condition="!Exists('$(BuildVersionFileDir)')" Directories="$(BuildVersionFileDir)" />

    <WriteLinesToFile
      ContinueOnError="WarnAndContinue"
      File="$(BuildVersionFilePath)"
      Lines="@(CurrentVersionLines)"
      Overwrite="true" />

    <!-- Delete old BuildVersion.props files -->
    <ItemGroup>
      <OldBuildVersionFiles Include="$(BuildVersionFilePath)BuildVersions-*.props" Exclude="$(BuildVersionFilePath)%(BuildVersionFileItem.Filename).props" />
    </ItemGroup>
    <Delete Files="@(OldBuildVersionFiles)" TreatErrorsAsWarnings="true"/>
  </Target>

  <UsingTask TaskName="FSharpEmbedResourceText"
             AssemblyFile="$(FSharpSourcesRoot)\..\Proto\net40\bin\FSharp.Build-proto.dll"
             Condition="'$(Configuration)' != 'Proto'" />
  <UsingTask TaskName="FSharpEmbedResXSource"
             AssemblyFile="$(FSharpSourcesRoot)\..\Proto\net40\bin\FSharp.Build-proto.dll"
             Condition="'$(Configuration)' != 'Proto'" />
  <UsingTask TaskName="WriteCodeFragment"
             AssemblyFile="$(FSharpSourcesRoot)\..\Proto\net40\bin\FSharp.Build-proto.dll"
             Condition="'$(Configuration)' != 'Proto'" />

  <Target Name="GenerateFSharpTextResources"
          BeforeTargets="GetXlfSources;CoreResGen;PrepareForBuild"
          Condition="'$(Configuration)' != 'Proto'">

    <MakeDir Directories="$(IntermediateOutputPath)" />

    <!-- Generate source for all resx files. -->
    <FSharpEmbedResXSource EmbeddedResource="@(EmbeddedResource)" IntermediateOutputPath="$(IntermediateOutputPath)" TargetFramework="$(TargetFramework)">
      <Output TaskParameter="GeneratedSource" ItemName="_FsGeneratedResXSource" />
    </FSharpEmbedResXSource>

    <ItemGroup>
      <CompileBefore Include="@(_FsGeneratedResXSource)" />
      <FileWrites Include="@(_FsGeneratedResXSource)" />
    </ItemGroup>

    <!-- Generate resx and source for all txt files. -->
    <FSharpEmbedResourceText EmbeddedText="@(EmbeddedText)" IntermediateOutputPath="$(IntermediateOutputPath)">
      <Output TaskParameter="GeneratedSource" ItemName="_FsGeneratedTxtSource" />
      <Output TaskParameter="GeneratedResx" ItemName="_FsGeneratedResx" />
    </FSharpEmbedResourceText>

    <ItemGroup>
      <CompileBefore Include="@(_FsGeneratedTxtSource)" />
      <EmbeddedResource Include="@(_FsGeneratedResx)" />
      <FileWrites Include="@(_FsGeneratedTxtSource)" />
      <FileWrites Include="@(_FsGeneratedResx)" />
    </ItemGroup>

  </Target>

  <PropertyGroup Condition="'$(Configuration)' != 'Proto'">
    <GeneratedFSharpInternalsVisibleToFile>$(IntermediateOutputPath)$(MSBuildProjectName).InternalsVisibleTo$(DefaultLanguageSourceExtension)</GeneratedFSharpInternalsVisibleToFile>
  </PropertyGroup>

  <ItemDefinitionGroup>
    <InternalsVisibleTo>
      <Visible>false</Visible>
    </InternalsVisibleTo>
  </ItemDefinitionGroup>

  <Target Name="PrepareFSharpGenerateInternalsVisibleToFile"
          Condition="'$(Configuration)' != 'Proto' and '@(InternalsVisibleTo)' != ''">
    <PropertyGroup>
      <_PublicKey>002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293</_PublicKey>
    </PropertyGroup>
    <ItemGroup>
      <_InternalsVisibleToAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
        <_Parameter1 Condition="'%(InternalsVisibleTo.Key)' != ''">%(InternalsVisibleTo.Identity), PublicKey=%(InternalsVisibleTo.Key)</_Parameter1>
        <_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == ''">%(InternalsVisibleTo.Identity), PublicKey=$(_PublicKey)</_Parameter1>
      </_InternalsVisibleToAttribute>
    </ItemGroup>
  </Target>

  <Target Name="GenerateFSharpInternalsVisibleToFile"
          Inputs="$(MSBuildProjectFile)"
          Outputs="$(GeneratedFSharpInternalsVisibleToFile)"
          DependsOnTargets="PrepareFSharpGenerateInternalsVisibleToFile;PrepareForBuild"
          Condition="'$(Configuration)' != 'Proto' and '@(InternalsVisibleTo)' != ''"
          BeforeTargets="CoreCompile">
    <WriteCodeFragment AssemblyAttributes="@(_InternalsVisibleToAttribute)"
                       Language="$(Language)"
                       OutputFile="$(GeneratedFSharpInternalsVisibleToFile)">
      <Output TaskParameter="OutputFile" ItemName="CompileBefore" />
      <Output TaskParameter="OutputFile" ItemName="FileWrites" />
    </WriteCodeFragment>
  </Target>

  <UsingTask TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
      <InputFilename ParameterType="System.String" Required="true" />
      <OutputFilename ParameterType="System.String" Required="true" />
      <MatchExpression ParameterType="System.String" Required="true" />
      <ReplacementText ParameterType="System.String" Required="true" />
    </ParameterGroup>
    <Task>
      <Reference Include="System.Core" />
      <Using Namespace="System" />
      <Using Namespace="System.IO" />
      <Using Namespace="System.Text.RegularExpressions" />
      <Code Type="Fragment" Language="cs">
        <![CDATA[
            File.WriteAllText(
                OutputFilename,
                Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
                );
          ]]>
      </Code>
    </Task>
  </UsingTask>

  <UsingTask TaskName="SetEnvVar" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
      <Name  ParameterType="System.String" Required="true" />
      <Value ParameterType="System.String" Required="true" />
    </ParameterGroup>
    <Task>
      <Using Namespace="System" />
      <Code Type="Fragment" Language="cs">
        <![CDATA[
          Environment.SetEnvironmentVariable(Name, Value);
        ]]>
      </Code>
    </Task>
  </UsingTask>

  </Project>
<commit_msg>use the $(DelaySign) value directly so later tools can consume the value<commit_after><?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) Microsoft Corporation.  All Rights Reserved.  See License.txt in the project root for license information. -->
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <FSCoreVersion>4.4.1.0</FSCoreVersion>
  </PropertyGroup>

  <Choose>
    <When Condition="'$(Configuration)' == 'Debug' or '$(Configuration)' == 'Release' ">
      <PropertyGroup>
        <SkipSigning>false</SkipSigning><!-- Skip using the ,net toolset to generate signing . -->
        <UseOpenSourceSign>true</UseOpenSourceSign>
      </PropertyGroup>
      <Choose>
        <When Condition="'$(ProjectLanguage)' == 'FSharp'">
          <Choose>
            <!-- Some unit test assemblies must not have strong names since they reference other assemblies that don't have strong names -->
            <!-- These unit test assemblies can't use InternalsVisibleTo into assemblies with strong names. -->
            <When Condition="'$(StrongNames)' == 'false'" >
              <PropertyGroup>
                <SkipSigning>true</SkipSigning>
                <UseOpenSourceSign>false</UseOpenSourceSign>
                <MicroBuildAssemblyVersion Condition="'$(MicroBuildAssemblyVersion)' == ''">$(FSCoreVersion)</MicroBuildAssemblyVersion>
                <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
              </PropertyGroup>
            </When>
            <!-- In the open source "Mono" build we always fully sign the binaries with the public test.snk, apart from FSharp.Core, which gets the MSFT key -->
            <When Condition="'$(MonoPackaging)' == 'true' AND '$(AssemblyName)'!='FSharp.Core'" >
              <PropertyGroup>
                <KeyOriginatorFile>$(FSharpSourcesRoot)\fsharp\test.snk</KeyOriginatorFile>
                <DefineConstants>STRONG_NAME_FSHARP_COMPILER_WITH_TEST_KEY;$(DefineConstants)</DefineConstants>
                <StrongNames>true</StrongNames>
                <MicroBuildAssemblyVersion Condition="'$(MicroBuildAssemblyVersion)' == ''">$(FSCoreVersion)</MicroBuildAssemblyVersion>
                <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
              </PropertyGroup>
            </When>
            <!-- In the Microsoft build we just delay-sign everything with the MSFT key -->
            <!-- We have to do unit test DLLs well because they can see the internals of other strong-named DLLs -->
            <Otherwise>
              <PropertyGroup>
                <SignAssembly>true</SignAssembly>
                <DelaySign>true</DelaySign>
                <AssemblyOriginatorKeyFile>$(FSharpSourcesRoot)\fsharp\msft.pubkey</AssemblyOriginatorKeyFile>
                <DefineConstants>STRONG_NAME_AND_DELAY_SIGN_FSHARP_COMPILER_WITH_MSFT_KEY;$(DefineConstants)</DefineConstants>
                <StrongNames>true</StrongNames>
                <MicroBuildAssemblyVersion>$(FSCoreVersion)</MicroBuildAssemblyVersion>
                <!-- certain delivered F# VS assemblies use a specific MicroBuildAssemblyVersion, otherwise use FSCoreVersion -->
                <MicroBuildAssemblyVersion Condition="'$(UseVsMicroBuildAssemblyVersion)' == 'true'">15.4.1.0</MicroBuildAssemblyVersion>
                <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
              </PropertyGroup>
            </Otherwise>
          </Choose>
        </When>
        <Otherwise>
          <!-- Not F# code -->
          <PropertyGroup>
            <SignAssembly>true</SignAssembly>
            <AssemblyOriginatorKeyFile>$(FSharpSourcesRoot)\fsharp\msft.pubkey</AssemblyOriginatorKeyFile>
            <DefineConstants>STRONG_NAME_AND_DELAY_SIGN_FSHARP_COMPILER_WITH_MSFT_KEY;$(DefineConstants)</DefineConstants>
            <StrongNames>true</StrongNames>
            <DelaySign>true</DelaySign>
            <MicroBuildAssemblyVersion>$(FSCoreVersion)</MicroBuildAssemblyVersion>
            <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
          </PropertyGroup>
        </Otherwise>
      </Choose>
    </When>
    <Otherwise>
      <PropertyGroup Condition="'$(StrongNames)' != 'true'">
        <!-- For the proto build we don't use strong names. -->
        <DefineConstants>NO_STRONG_NAMES;$(DefineConstants)</DefineConstants>
        <MicroBuildAssemblyVersion>$(FSCoreVersion)</MicroBuildAssemblyVersion>
        <MicroBuildAssemblyFileLanguage>fs</MicroBuildAssemblyFileLanguage>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup Condition="'$(UseMicroBuild)' != 'true'">
    <OtherFlags >$(OtherFlags) --version:"$(MicroBuildAssemblyVersion)"</OtherFlags>
  </PropertyGroup>

  <PropertyGroup Condition="'$(UseSourceLink)' == 'true'">
    <SourceLink>$(IntermediateOutputPath)source_link.json</SourceLink>
  </PropertyGroup>

  <PropertyGroup Condition="'$(StrongNames)' != 'true'">
    <DefineConstants>NO_STRONG_NAMES;$(DefineConstants)</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(MonoPackaging)' != 'true'">
    <DefineConstants>MSBUILD_AT_LEAST_14;$(DefineConstants)</DefineConstants>
  </PropertyGroup>

  <PropertyGroup>
    <!-- Disable uwa toolchain nuget package resolve logic. -->
    <NuGetTargets  Condition="'$(NuGetTargets)' == ''">false</NuGetTargets>
  </PropertyGroup>  

  <PropertyGroup>
    <NugetLocalPackagesDir>$(FSharpSourcesRoot)\..\packages</NugetLocalPackagesDir>
    <NUnitVersion>3.5.0</NUnitVersion>
    <NUnitFullVersion>3.5.0.0</NUnitFullVersion>
    <NUnitLibDir>$(FSharpSourcesRoot)\..\packages\NUnit.$(NUnitVersion)\lib\net45</NUnitLibDir>
    <NUnitToolsLibDir>$(FSharpSourcesRoot)\..\packages\NUnit.ConsoleRunner\$(NUnitVersion)\tools\</NUnitToolsLibDir>
    <FsCheckVersion>2.6.2</FsCheckVersion>
    <FsCheckFullVersion>2.6.2.0</FsCheckFullVersion>
    <FsCheckLibDir>$(FSharpSourcesRoot)\..\packages\FsCheck.$(FsCheckVersion)\lib\</FsCheckLibDir>
  </PropertyGroup>

  <Import Project="FSharpSource.Profiles.targets" />

  <PropertyGroup Condition="'$(TargetDotnetProfile)'=='net40'">
    <TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v4.5</TargetFrameworkVersion>
    <TargetFrameworkProfile></TargetFrameworkProfile>
    <!-- MSbuild works out the assembly references -->
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetDotnetProfile)'=='coreclr'">
    <TargetProfile>netcore</TargetProfile>
    <TargetFrameworkProfile></TargetFrameworkProfile>                                   <!-- We are currently directly referencing corefx assemblies, so profile7 is not really true -->
    <TargetFrameworkVersion Condition="'$(TargetFrameworkVersion)' == ''">v5.0</TargetFrameworkVersion>
    <ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework>            <!-- To stop msbuild being helpful and referencing the dlls for the profile -->
    <NuGetTargetMoniker>.NETStandard,Version=v1.6</NuGetTargetMoniker>
    <PortableNuGetMode>true</PortableNuGetMode>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(TargetDotnetProfile)'=='coreclr' AND '$(DOTNET_PUBLISH_TEST)'=='true' ">
    <OutputPath>bin\$(Configuration)\netcoreapp1.0</OutputPath>
    <CustomOutputPath>true</CustomOutputPath>
    <DOTNET_PUBLISH>true</DOTNET_PUBLISH>
    <DOTNET_PUBLISH_PLATFORM>win7-x64</DOTNET_PUBLISH_PLATFORM>
    <DOTNET_PUBLISH_PATH>$(FSharpSourcesRoot)\..\tests\testbin\$(Configuration)\coreclr\$(AssemblyName)</DOTNET_PUBLISH_PATH>
    <OutputType>Exe</OutputType>
    <TargetExt>.dll</TargetExt>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(TargetDotnetProfile)'=='coreclr' AND '$(DOTNET_PUBLISH_COMPILERS)'=='true' ">
    <DOTNET_PUBLISH_FSC>true</DOTNET_PUBLISH_FSC>
    <DOTNET_PUBLISH_FSC_PATH>$(FSharpSourcesRoot)\..\tests\testbin\$(Configuration)\coreclr\FSC</DOTNET_PUBLISH_FSC_PATH>
    <DOTNET_PUBLISH_FSI>true</DOTNET_PUBLISH_FSI>
    <DOTNET_PUBLISH_FSI_PATH>$(FSharpSourcesRoot)\..\tests\testbin\$(Configuration)\coreclr\FSC</DOTNET_PUBLISH_FSI_PATH>
  </PropertyGroup>

  <!-- If building an FSharp.Core for a back version (Mono Debian source builds only), put it in a qualified directory -->
  <PropertyGroup>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == ''">$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == '3.0'">fsharp30\$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == '3.1'">fsharp31\$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <TargetFrameworkOutputDirectory Condition="'$(FSharpCoreBackVersion)' == '4.0'">fsharp40\$(TargetDotnetProfile)</TargetFrameworkOutputDirectory>
    <IntermediateOutputPath>obj\$(TargetFrameworkOutputDirectory)\</IntermediateOutputPath>
  </PropertyGroup>

  <Choose>
    <When Condition="'$(BuildWith)' == 'LKG' AND '$(BUILD_PROTO_WITH_CORECLR_LKG)' == '1'">
      <PropertyGroup >
        <OutputPath>$(FSharpSourcesRoot)\..\$(Configuration)\$(ProtoFlavour)\bin</OutputPath>
        <!-- When using coreclr to bootstrap to proto. We acquire the FSharp.Core LKG, targets LKG, the FSharp.Build LKG from the .NET Framework compiler tools LKG package. -->
        <FSharpNetCoreLkgPath>$(FSharpSourcesRoot)\..\Tools\dotnet20\sdk\2.0.0-preview2-006502\FSharp</FSharpNetCoreLkgPath>
        <FSharpTargetsPath>..\packages\FSharp.Compiler.Tools.4.1.27\tools\Microsoft.FSharp.Targets</FSharpTargetsPath>

        <!-- When using coreclr to bootstrap, the compiler binary comes from the coreclr LKG, invoked using corehost.exe -->
        <FscToolPath>$(FSharpSourcesRoot)\..\Tools\dotnet20</FscToolPath>
        <FscToolExe Condition="'$(OS)' != 'Unix'">dotnet.exe</FscToolExe>
        <FscToolExe Condition="'$(OS)' == 'Unix'">dotnet</FscToolExe>
        <DotnetFscCompilerPath>$(FSharpNetCoreLkgPath)\fsc.exe</DotnetFscCompilerPath>
      </PropertyGroup>
    </When>
    <When Condition="'$(BuildWith)' == 'LKG' AND '$(BUILD_PROTO_WITH_CORECLR_LKG)' != '1'">
       <!-- Use .NET Framework to bootstrap to proto -->
      <PropertyGroup >
        <OutputPath>$(FSharpSourcesRoot)\..\$(Configuration)\$(ProtoFlavour)\bin</OutputPath>
        <FSharpTargetsPath>..\packages\FSharp.Compiler.Tools.4.1.27\tools\Microsoft.FSharp.Targets</FSharpTargetsPath>
      </PropertyGroup>
    </When>
    <When Condition="'$(BuildWith)' == '' AND '$(TargetDotnetProfile)'=='coreclr'">
      <!-- Compiling coreclr with Proto, currently always use a .NET Framework/Mono proto -->
      <PropertyGroup>
        <OutputPath Condition=" '$(CustomOutputPath)' != 'true' ">$(FSharpSourcesRoot)\..\$(Configuration)\$(TargetFrameworkOutputDirectory)\bin</OutputPath>
        <FscToolPath>$(FSharpSourcesRoot)\..\Proto\$(ProtoFlavour)\bin</FscToolPath>
        <FscToolExe>fsc-proto.exe</FscToolExe>
        <FSharpTargetsPath>..\Proto\$(ProtoFlavour)\bin\Microsoft.Portable.FSharp-proto.targets</FSharpTargetsPath>
      </PropertyGroup>
    </When>
    <Otherwise>
      <!-- Compiling net40 with Proto -->
      <PropertyGroup>
        <OutputPath Condition=" '$(CustomOutputPath)' != 'true' ">$(FSharpSourcesRoot)\..\$(Configuration)\$(TargetFrameworkOutputDirectory)\bin</OutputPath>
        <FscToolPath>$(FSharpSourcesRoot)\..\Proto\$(ProtoFlavour)\bin</FscToolPath>
        <FscToolExe>fsc-proto.exe</FscToolExe>
        <FSharpTargetsPath>..\Proto\$(ProtoFlavour)\bin\Microsoft.FSharp-proto.targets</FSharpTargetsPath>
      </PropertyGroup>
    </Otherwise>
  </Choose>

  <PropertyGroup>
    <CompileDependsOn>ValidateBuildTools;$(CompileDependsOn)</CompileDependsOn>
  </PropertyGroup>

  <Target Name="ValidateBuildTools" Condition="'$(ProjectLanguage)' == 'FSharp'" >
    <Message Text="FSharpTargetsPath = $(FSharpTargetsPath)" />
    <Message Text="FSharpSourcesRoot = $(FSharpSourcesRoot)" />
    <Message Text="FscToolPath = $(FscToolPath)" />
    <Message Text="FsiToolPath = $(FsiToolPath)" />
    <Message Text="FsLexToolPath = $(FsLexToolPath)" />
    <Message Text="FsYaccToolPath = $(FsYaccToolPath)" />
    <Message Text="ToolsDir = $(ToolsDir)" />
    <Error Text="Expect $(FSharpTargetsPath) to exist" Condition="'!Exists('$(FSharpTargetsPath)')" />
    <Error Text="Expect $(FSharpNetCoreLkgPath)\fsc.exe to exist when BUILD_PROTO_WITH_CORECLR_LKG==1" Condition="'$(BUILD_PROTO_WITH_CORECLR_LKG)' == 1 AND !Exists('$(FSharpNetCoreLkgPath)\fsc.exe')" />
    <Error Text="Expect $(FscToolPath)\$(FscToolExe) to exist" Condition="!Exists('$(FscToolPath)\$(FscToolExe)')" />
    <Error Text="Expect $(DotnetFscCompilerPath) to exist if non-empty" Condition="'$(DotnetFscCompilerPath)' != '' AND !Exists('$(DotnetFscCompilerPath)')" />
    <Error Text="Expect $(FsiToolPath)\$(FsiToolExe) to exist" Condition="!Exists('$(FsiToolPath)\$(FsiToolExe)')" />
    <Error Text="Expect $(FsLexToolPath)\$(FsLexToolExe) to exist" Condition="!Exists('$(FsLexToolPath)\$(FsLexToolExe)')" />
    <Error Text="Expect $(FsYaccToolPath)\$(FsYaccToolExe) to exist" Condition="!Exists('$(FsYaccToolPath)\$(FsYaccToolExe)')" />
  </Target>

  <Import Condition="'$(ProjectLanguage)' == 'FSharp'" Project="$(FSharpTargetsPath)"/>

  <!-- Hook up .NET Core to enable solution refresh of packages -->
  <PropertyGroup Condition="'$(TargetDotnetProfile)'=='coreclr'">

    <!-- Implicitly needed by packageresolve.targets.  Should file a bug for a better error message here -->
    <PackagesDir>$(NUGET_PACKAGES)</PackagesDir>

    <NuGetToolPath Condition="'$(NuGetToolPath)' == ''">$(FSharpSourcesRoot)\..\.nuget\</NuGetToolPath>
    <NuGetConfigCommandLine>-ConfigFile "$(NuGetConfigFile)"</NuGetConfigCommandLine>
    <NugetRestoreCommand>"$(NuGetToolPath)NuGet.exe install -OutputDirectory "$(PackagesDir)" -Config "$(NuGetToolPath)NuGet.Config"</NugetRestoreCommand>
    <DnuRestoreCommand>"$(NuGetToolPath)NuGet.exe" restore -OutputDirectory "$(PackagesDir)" -Config "$(NuGetToolPath)NuGet.Config"</DnuRestoreCommand>

    <!-- Current version of .NET Core does not support all semantics used in our packages, 
         so we ignore the pre-calculation in the lock file and calculate asset applicability in the build task -->
    <NuGetIngoreLockFile>true</NuGetIngoreLockFile>
  </PropertyGroup>
  <Import  Condition="'$(TargetDotnetProfile)'=='coreclr'" Project="..\Tools\Build.Common.Targets" />

  <PropertyGroup>
    <RootNamespace></RootNamespace>
    <DocumentationFile>$(OutputPath)$(AssemblyName).xml</DocumentationFile>
  </PropertyGroup>

  <PropertyGroup>
    <PackageLicenceUrl Condition="'$(PackageLicenceUrl)' == ''">https://github.com/Microsoft/visualfsharp/blob/master/License.txt</PackageLicenceUrl>
    <PackageProjectUrl Condition="'$(PackageProjectUrl)' == ''">https://github.com/Microsoft/visualfsharp</PackageProjectUrl>
    <PackageVersion    Condition="'$(PackageVersion)' == ''"   >$(NuGetPerBuildPreReleaseVersion)</PackageVersion>
    <PackageAuthors    Condition="'$(PackageAuthors)' == ''"   >Microsoft</PackageAuthors>
    <PackageTags       Condition="'$(PackageTags)' == ''"      >Visual F# Compiler FSharp coreclr functional programming</PackageTags>
  </PropertyGroup>

  <!-- This build step copies files to the output folder while replacing build variables in the text of those file. -->
  <PropertyGroup>
    <CompileDependsOn>$(CompileDependsOn);CopyAndSubstituteTextFiles</CompileDependsOn>
  </PropertyGroup>

  <Target
          Name="CopyAndSubstituteTextFiles"
          Inputs="@(CopyAndSubstituteText)"
          Outputs="@(CopyAndSubstituteText->'$(OutDir)%(TargetFilename)')"  >
    <Exec Command="&quot;$([System.IO.Path]::GetFullPath('$(FsiToolPath)\$(FsiToolExe)'))&quot; --exec &quot;$(MSBuildThisFileDirectory)scripts/subst.fsx&quot; --in:&quot;%(CopyAndSubstituteText.FullPath)&quot; --out:&quot;$(OutDir)%(CopyAndSubstituteText.TargetFilename)&quot; --pattern1:&quot;%(CopyAndSubstituteText.Pattern1)&quot; --replacement1:&quot;%(CopyAndSubstituteText.Replacement1)&quot; --pattern2:&quot;%(CopyAndSubstituteText.Pattern2)&quot; --replacement2:&quot;%(CopyAndSubstituteText.Replacement2)&quot; " Condition="'$(OS)' != 'Unix'" />
    <Exec Command="mono $([System.IO.Path]::GetFullPath('$(FsiToolPath)\$(FsiToolExe)')) --exec &quot;$(MSBuildThisFileDirectory)scripts/subst.fsx&quot; --in:&quot;%(CopyAndSubstituteText.FullPath)&quot; --out:&quot;$(OutDir)%(CopyAndSubstituteText.TargetFilename)&quot; --pattern1:&quot;%(CopyAndSubstituteText.Pattern1)&quot; --replacement1:&quot;%(CopyAndSubstituteText.Replacement1)&quot; --pattern2:&quot;%(CopyAndSubstituteText.Pattern2)&quot; --replacement2:&quot;%(CopyAndSubstituteText.Replacement2)&quot; " Condition="'$(OS)' == 'Unix'" />
    <!-- Make sure it will get cleaned  -->
    <CreateItem Include="$(OutDir)%(CopyAndSubstituteText.TargetFilename)">
      <Output TaskParameter="Include" ItemName="FileWrites"/>
    </CreateItem>
  </Target>
  <Import Project="$(FSharpSourcesRoot)\scripts\fssrgen.targets" Condition="'$(Configuration)' == 'Proto'" />
  <Import Project="Microbuild.Settings.targets" Condition="'$(UseMicroBuild)' == 'true'"/>

  <Target Name="dotnetrestore" BeforeTargets="Build" Condition=" '$(TargetDotnetProfile)' == 'coreclr' ">
   <Exec Command="$(MSBuildThisFileDirectory)..\.nuget\nuget.exe restore -PackagesDirectory $(PackagesDir) -Config $(MSBuildThisFileDirectory)..\.nuget\NuGet.Config project.json" />
  </Target>

  <Target Name="dotnetrestore" BeforeTargets="Build" Condition=" '$(DOTNET_PUBLISH)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe restore &#45;&#45;configfile $(MSBuildThisFileDirectory)..\.nuget\NuGet.Config project.json"/>
  </Target>

  <Target Name="dotnetpublish" AfterTargets="Build" Condition=" '$(DOTNET_PUBLISH)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe &#45;&#45;verbose publish &#45;&#45;no-build project.json -r $(DOTNET_PUBLISH_PLATFORM) -c $(Configuration) -o $(DOTNET_PUBLISH_PATH)"/>
  </Target>

  <Target Name="dotnetpublishfsccompiler" AfterTargets="CopyFilesToOutputDirectory" Condition=" '$(DOTNET_PUBLISH_FSC)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe restore DeployCompiler\fsc\project.json"/>
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe &#45;&#45;verbose publish &#45;&#45;no-build DeployCompiler\fsc\project.json -r $(DOTNET_PUBLISH_PLATFORM) -c $(Configuration) -o $(DOTNET_PUBLISH_FSC_PATH)"/>
  </Target>

  <Target Name="dotnetpublishfsicompiler" AfterTargets="CopyFilesToOutputDirectory" Condition=" '$(DOTNET_PUBLISH_FSI)' == 'true' ">
    <SetEnvVar Name="NUGET_PACKAGES" Value="$(NUGET_PACKAGES)" />
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe restore DeployCompiler\fsi\project.json"/>
    <Exec Command="$(MSBuildThisFileDirectory)..\Tools\dotnetcli\dotnet.exe &#45;&#45;verbose publish &#45;&#45;no-build DeployCompiler\fsi\project.json -r $(DOTNET_PUBLISH_PLATFORM) -c $(Configuration) -o $(DOTNET_PUBLISH_FSI_PATH)"/>
  </Target>

  <Target Name="GenerateSourceLink" BeforeTargets="CoreCompile" Condition="'$(UseSourceLink)' == 'true'">
    <PropertyGroup>
      <SrcRootDirectory>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory.TrimEnd("\"))))</SrcRootDirectory>
      <SourceLinkRoot>$(SrcRootDirectory.Replace("\", "\\"))</SourceLinkRoot>
    </PropertyGroup>

    <Exec Command="git config --get remote.origin.url" ConsoleToMsBuild="true">
      <Output TaskParameter="ConsoleOutput" PropertyName="RemoteUri" />
    </Exec>

    <!-- https://raw.githubusercontent.com/KevinRansom/visualfsharp/98e8c9a2ca09a36ebd024eb424fc050a831053cd/build.cmd  -->
    <Exec Command="git rev-parse HEAD" ConsoleToMsBuild="true" Condition = " '$(TF_BUILD)' != 'True' ">
      <Output TaskParameter="ConsoleOutput" PropertyName="LatestCommit" />
    </Exec>

    <Exec Command="git merge-base --fork-point refs/remotes/visualfsharptools/master HEAD" ConsoleToMsBuild="true" Condition = " '$(TF_BUILD)' == 'True' ">
      <Output TaskParameter="ConsoleOutput" PropertyName="LatestCommit" />
    </Exec>

    <WriteLinesToFile File="$(IntermediateOutputPath)source_link.json" Overwrite="true" Lines='{"documents": { "$(SourceLinkRoot)\\*" : "$(RemoteUri.Replace(".git", "").Replace("github.com", "raw.githubusercontent.com"))/$(LatestCommit)/*" }}' />
  </Target>

    <!-- If BuildVersionFilePath not specified then do nothing  -->
  <Target Name="CleanVersionFile" Condition ="'$(BuildVersionFilePath)' != '' ">
    <PropertyGroup>
        <BuildVersionFileDir>$([System.IO.Path]::GetDirectoryName($(BuildVersionFilePath)))</BuildVersionFileDir>
    </PropertyGroup>
    <RemoveDir Condition="Exists('$(BuildVersionFileDir)')" Directories="$(BuildVersionFileDir)" />
  </Target>

    <!-- If BuildVersionFilePath not specified then do nothing  -->
  <Target Name="CreateOrUpdateBuildVersionFile" Condition ="'$(BuildVersionFilePath)' != '' ">
    <PropertyGroup>
        <BuildVersionFileDir>$([System.IO.Path]::GetDirectoryName($(BuildVersionFilePath)))</BuildVersionFileDir>
        <PackageVersionMajor Condition="'$(PackageVersionMajor)' == ''" >$(NuGetPerBuildPreReleaseVersion)</PackageVersionMajor>
        <PackageVersionMinor Condition="'$(PackageVersionMinor)' != ''" >$([MSBuild]::Add($(PackageVersionMinor), 1))</PackageVersionMinor>
        <PackageVersionMinor Condition="'$(PackageVersionMinor)' == ''" >1</PackageVersionMinor>
    </PropertyGroup>

    <ItemGroup>
      <CurrentVersionLines Include="%3C%3Fxml version=%221.0%22 encoding=%22utf-8%22%3F%3E" />
      <CurrentVersionLines Include="%3C!-- This is a generated file. $(VersionSeedSourceComment) Seed Date is $(VersionSeedDate). --%3E" />
      <CurrentVersionLines Include="%3CProject xmlns=%22http://schemas.microsoft.com/developer/msbuild/2003%22%3E" />
      <CurrentVersionLines Include="%3CPropertyGroup%3E" />
      <CurrentVersionLines Include="%3CPackageVersionMajor Condition=%22%27%24(PackageVersionMajor)%27==%27%27%22%3E$(NuGetPerBuildPreReleaseVersion)%3C/PackageVersionMajor%3E" />
      <CurrentVersionLines Include="%3CPackageVersionMinor Condition=%22%27%24(PackageVersionMinor)%27==%27%27%22%3E$(PackageVersionMinor)%3C/PackageVersionMinor%3E" />
      <CurrentVersionLines Include="%3C/PropertyGroup%3E" />
      <CurrentVersionLines Include="%3C/Project%3E" />
    </ItemGroup>

    <!-- Since by default the file will get dropped at the obj dir, make sure that the dir is created already or else WriteLinesToFile will error. -->
    <MakeDir Condition="!Exists('$(BuildVersionFileDir)')" Directories="$(BuildVersionFileDir)" />

    <WriteLinesToFile
      ContinueOnError="WarnAndContinue"
      File="$(BuildVersionFilePath)"
      Lines="@(CurrentVersionLines)"
      Overwrite="true" />

    <!-- Delete old BuildVersion.props files -->
    <ItemGroup>
      <OldBuildVersionFiles Include="$(BuildVersionFilePath)BuildVersions-*.props" Exclude="$(BuildVersionFilePath)%(BuildVersionFileItem.Filename).props" />
    </ItemGroup>
    <Delete Files="@(OldBuildVersionFiles)" TreatErrorsAsWarnings="true"/>
  </Target>

  <UsingTask TaskName="FSharpEmbedResourceText"
             AssemblyFile="$(FSharpSourcesRoot)\..\Proto\net40\bin\FSharp.Build-proto.dll"
             Condition="'$(Configuration)' != 'Proto'" />
  <UsingTask TaskName="FSharpEmbedResXSource"
             AssemblyFile="$(FSharpSourcesRoot)\..\Proto\net40\bin\FSharp.Build-proto.dll"
             Condition="'$(Configuration)' != 'Proto'" />
  <UsingTask TaskName="WriteCodeFragment"
             AssemblyFile="$(FSharpSourcesRoot)\..\Proto\net40\bin\FSharp.Build-proto.dll"
             Condition="'$(Configuration)' != 'Proto'" />

  <Target Name="GenerateFSharpTextResources"
          BeforeTargets="GetXlfSources;CoreResGen;PrepareForBuild"
          Condition="'$(Configuration)' != 'Proto'">

    <MakeDir Directories="$(IntermediateOutputPath)" />

    <!-- Generate source for all resx files. -->
    <FSharpEmbedResXSource EmbeddedResource="@(EmbeddedResource)" IntermediateOutputPath="$(IntermediateOutputPath)" TargetFramework="$(TargetFramework)">
      <Output TaskParameter="GeneratedSource" ItemName="_FsGeneratedResXSource" />
    </FSharpEmbedResXSource>

    <ItemGroup>
      <CompileBefore Include="@(_FsGeneratedResXSource)" />
      <FileWrites Include="@(_FsGeneratedResXSource)" />
    </ItemGroup>

    <!-- Generate resx and source for all txt files. -->
    <FSharpEmbedResourceText EmbeddedText="@(EmbeddedText)" IntermediateOutputPath="$(IntermediateOutputPath)">
      <Output TaskParameter="GeneratedSource" ItemName="_FsGeneratedTxtSource" />
      <Output TaskParameter="GeneratedResx" ItemName="_FsGeneratedResx" />
    </FSharpEmbedResourceText>

    <ItemGroup>
      <CompileBefore Include="@(_FsGeneratedTxtSource)" />
      <EmbeddedResource Include="@(_FsGeneratedResx)" />
      <FileWrites Include="@(_FsGeneratedTxtSource)" />
      <FileWrites Include="@(_FsGeneratedResx)" />
    </ItemGroup>

  </Target>

  <PropertyGroup Condition="'$(Configuration)' != 'Proto'">
    <GeneratedFSharpInternalsVisibleToFile>$(IntermediateOutputPath)$(MSBuildProjectName).InternalsVisibleTo$(DefaultLanguageSourceExtension)</GeneratedFSharpInternalsVisibleToFile>
  </PropertyGroup>

  <ItemDefinitionGroup>
    <InternalsVisibleTo>
      <Visible>false</Visible>
    </InternalsVisibleTo>
  </ItemDefinitionGroup>

  <Target Name="PrepareFSharpGenerateInternalsVisibleToFile"
          Condition="'$(Configuration)' != 'Proto' and '@(InternalsVisibleTo)' != ''">
    <PropertyGroup>
      <_PublicKey>002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293</_PublicKey>
    </PropertyGroup>
    <ItemGroup>
      <_InternalsVisibleToAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
        <_Parameter1 Condition="'%(InternalsVisibleTo.Key)' != ''">%(InternalsVisibleTo.Identity), PublicKey=%(InternalsVisibleTo.Key)</_Parameter1>
        <_Parameter1 Condition="'%(InternalsVisibleTo.Key)' == ''">%(InternalsVisibleTo.Identity), PublicKey=$(_PublicKey)</_Parameter1>
      </_InternalsVisibleToAttribute>
    </ItemGroup>
  </Target>

  <Target Name="GenerateFSharpInternalsVisibleToFile"
          Inputs="$(MSBuildProjectFile)"
          Outputs="$(GeneratedFSharpInternalsVisibleToFile)"
          DependsOnTargets="PrepareFSharpGenerateInternalsVisibleToFile;PrepareForBuild"
          Condition="'$(Configuration)' != 'Proto' and '@(InternalsVisibleTo)' != ''"
          BeforeTargets="CoreCompile">
    <WriteCodeFragment AssemblyAttributes="@(_InternalsVisibleToAttribute)"
                       Language="$(Language)"
                       OutputFile="$(GeneratedFSharpInternalsVisibleToFile)">
      <Output TaskParameter="OutputFile" ItemName="CompileBefore" />
      <Output TaskParameter="OutputFile" ItemName="FileWrites" />
    </WriteCodeFragment>
  </Target>

  <UsingTask TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
      <InputFilename ParameterType="System.String" Required="true" />
      <OutputFilename ParameterType="System.String" Required="true" />
      <MatchExpression ParameterType="System.String" Required="true" />
      <ReplacementText ParameterType="System.String" Required="true" />
    </ParameterGroup>
    <Task>
      <Reference Include="System.Core" />
      <Using Namespace="System" />
      <Using Namespace="System.IO" />
      <Using Namespace="System.Text.RegularExpressions" />
      <Code Type="Fragment" Language="cs">
        <![CDATA[
            File.WriteAllText(
                OutputFilename,
                Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText)
                );
          ]]>
      </Code>
    </Task>
  </UsingTask>

  <UsingTask TaskName="SetEnvVar" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
    <ParameterGroup>
      <Name  ParameterType="System.String" Required="true" />
      <Value ParameterType="System.String" Required="true" />
    </ParameterGroup>
    <Task>
      <Using Namespace="System" />
      <Code Type="Fragment" Language="cs">
        <![CDATA[
          Environment.SetEnvironmentVariable(Name, Value);
        ]]>
      </Code>
    </Task>
  </UsingTask>

  </Project>

{'fraction_non_alphanumeric': 0.15355425824175825, 'fraction_numerical': 0.015865384615384615, 'mean_word_length': 4.759023039651933, 'pattern_counts': {'":': 2, '<': 1005, '<?xml version=': 4, '>': 1007, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 8, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1040831', 'n_tokens_mistral': 18851, 'n_tokens_neox': 16680, 'n_words': 2497}