title: msbuild and dotnet load different versions of Sdk.targets
body: <p>When I run <code>msbuild /bl /v:q /nologo /restore</code> it loads Sdk.props from <code>c:\Program Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\Sdk</code></p>
  
  <p>However, when I run <code>dotnet /bl /v:q /nologo</code> on the same exact machine I can see that Sdk.props is loaded from <code>c:\Program Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\Sdk</code></p>
  
  <p>Why is the difference? How can I cause <code>dotnet</code> to load the same Sdk as <code>msbuild</code>?</p>
  
  <p>The project file is this:</p>
  
  <pre><code>&lt;Project Sdk="Microsoft.NET.Sdk"&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netstandard2&lt;/TargetFramework&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup&gt;
      &lt;PackageReference Include="DbUpgradeApi" Version="1.0.363.6" /&gt;
      &lt;PackageReference Include="Newtonsoft.Json" Version="12.0.1" /&gt;
    &lt;/ItemGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p><strong>EDIT 1</strong></p>
  
  <pre><code>C:\xyz\LogDbUpgradeProgress [master ≡]&gt; dotnet --info
  .NET Core SDK (reflecting any global.json):
   Version:   2.1.502
   Commit:    c74ce8f29f
  
  Runtime Environment:
   OS Name:     Windows
   OS Version:  10.0.16299
   OS Platform: Windows
   RID:         win10-x64
   Base Path:   C:\Program Files\dotnet\sdk\2.1.502\
  
  Host (useful for support):
    Version: 2.1.6
    Commit:  3f4f8eebd8
  
  .NET Core SDKs installed:
    1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk]
    2.1.4 [C:\Program Files\dotnet\sdk]
    2.1.403 [C:\Program Files\dotnet\sdk]
    2.1.500 [C:\Program Files\dotnet\sdk]
    2.1.502 [C:\Program Files\dotnet\sdk]
  
  .NET Core runtimes installed:
    Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
    Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
    Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
    Microsoft.NETCore.App 1.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 2.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
    Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  
  To install additional .NET Core runtimes or SDKs:
    https://aka.ms/dotnet-download
  C:\xyz\LogDbUpgradeProgress [master ≡]&gt; Test-Path global.json
  False
  C:\xyz\LogDbUpgradeProgress [master ≡]&gt; Test-Path ..\global.json
  False
  C:\xyz\LogDbUpgradeProgress [master ≡]&gt; Test-Path ..\..\global.json
  False
  C:\xyz\LogDbUpgradeProgress [master ≡]&gt;
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>To demonstrate the point that builds work differently:</p>
  
  <pre><code>C:\xyz\LogDbUpgradeProgress [master ≡]&gt; msbuild /v:diag &gt; msbuild.diag.log
  C:\xyz\LogDbUpgradeProgress [master ≡ +1 ~0 -0 !]&gt; dotnet build /v:diag &gt; dotnet.diag.log
  C:\xyz\LogDbUpgradeProgress [master ≡ +2 ~0 -0 !]&gt; cat .\msbuild.diag.log | sls "\bSdk\.targets" | select -First 1
  
  Property reassignment: $(MSBuildAllProjects)=";C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props;C:\xyz\LogDbUpgradeProgress\Directory.Build.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.SupportedTargetFrameworks.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CSharp.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets" (previous value: ";C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props;C:\xyz\LogDbUpgradeProgress\Directory.Build.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.SupportedTargetFrameworks.props;C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CSharp.props") at C:\Program
  Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets (15,5)
  
  
  C:\xyz\LogDbUpgradeProgress [master ≡ +2 ~0 -0 !]&gt; cat .\dotnet.diag.log | sls "\bSdk\.targets" | select -First 1
  
                     Property reassignment: $(MSBuildAllProjects)=";c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props;C:\xyz\LogDbUpgradeProgress\Directory.Build.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.SupportedTargetFrameworks.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.CSharp.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets" (previous value: ";c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props;C:\xyz\LogDbUpgradeProgress\Directory.Build.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.SupportedTargetFrameworks.props;c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.CSharp.props") at c:\Program
  Files\dotnet\sdk\2.1.4\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets (15,5)
  
  
  C:\xyz\LogDbUpgradeProgress [master ≡ +2 ~0 -0 !]&gt; cat .\dotnet.diag.log | sls -SimpleMatch "2.1.502\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.target
  s" | select -First 1
  C:\xyz\LogDbUpgradeProgress [master ≡ +2 ~0 -0 !]&gt;
  </code></pre>
  
  <p>As you can see the diag log of msbuild reference Sdk.targets from 2.1.502 whereas the diag build of dotnet never references that version and instead goes for 2.1.4</p>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>Another way to recognize the difference is by passing the SourceRevisionId property. The newer Sdk.Targets makes use of it, the older does not. Please, observe (using another project):</p>
  
  <pre><code>C:\xyz\DbUpgradeApi [master ≡]&gt; git clean -qdfx
  C:\xyz\DbUpgradeApi [master ≡]&gt; msbuild /restore /v:q /p:SourceRevisionId=123
  Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  C:\xyz\DbUpgradeApi [master ≡]&gt; (dir .\src\bin\Debug\net452\DbUpgradeApi.dll).VersionInfo.ProductVersion
  1.0.0+123
  C:\xyz\DbUpgradeApi [master ≡]&gt; git clean -qdfx
  C:\xyz\DbUpgradeApi [master ≡]&gt; dotnet build /v:q /p:SourceRevisionId=123
  Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
  Copyright (C) Microsoft Corporation. All rights reserved.
  
  
  Build succeeded.
      0 Warning(s)
      0 Error(s)
  
  Time Elapsed 00:00:01.15
  C:\xyz\DbUpgradeApi [master ≡]&gt; (dir .\src\bin\Debug\net452\DbUpgradeApi.dll).VersionInfo.ProductVersion
  1.0.0
  C:\xyz\DbUpgradeApi [master ≡]&gt;
  </code></pre>
  
  <p>One can see that <code>dotnet</code> invokes a different version of msbuild - <code>15.9.20+g88f5fadfbe</code> vs <code>15.9.21+g9802d43bc3</code>. But I do not think it is a problem, since this is the msbuild.dll from <code>C:\Program Files\dotnet\sdk\2.1.502</code> which seems to be the right location.</p>