Boris Nikitin
Boris Nikitin

Reputation: 429

Setting of BaseIntermediateOutputPath prevents running .targets from Nuget

I have MSVS 2017 (15.3) and the following problem. My project references System.Data.SQLite which contains targets file that copies some native dlls to output folder. All works correctly (dlls appear in correct place) until I specify value for BaseIntermediateOutputPath parameter in props file. After setting parameter build is successful but dlls are missing.

Project file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net452</TargetFramework>
  </PropertyGroup>
  <Import Project="common.net.props" />
  <ItemGroup>
    <PackageReference Include="System.Data.SQLite" Version="1.0.105.2" />
 </ItemGroup>

Imported props has the following content

<Project>
  <PropertyGroup>
    <SolutionDir>$(MSBuildThisFileDirectory)</SolutionDir>
    <Configuration Condition="$(Configuration) == ''">Debug</Configuration>
  </PropertyGroup>
  <PropertyGroup>
    <SynOutDir>$(TargetFramework)_$(Platform)_$(Configuration)</SynOutDir>
  </PropertyGroup>
  <PropertyGroup>
    <BaseOutputPath>../bin/</BaseOutputPath>
    <BaseIntermediateOutputPath>../tmp/$(MSBuildProjectName)/</BaseIntermediateOutputPath>
    <OutputPath>$(BaseOutputPath)$(SynOutDir)</OutputPath>
    <OutDir>$(OutputPath)</OutDir>
    <LangVersion>7</LangVersion>
  </PropertyGroup>
</Project>

Upvotes: 0

Views: 1459

Answers (1)

natemcmaster
natemcmaster

Reputation: 26823

You've hit a known issue in MSBuild caused by import order. In MSBuild 15, the "SDK" attribute on <Project> is an implicit top/bottom import. Your import happens too late.

Changing the order should solve the issue. You could do it like this:

<Project>
   <Import Project="common.net.props" />
   <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />

   <!-- the rest of your project -->
   <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>

You can also name your file "Directory.Build.props" and it will magically be imported for you. See https://github.com/Microsoft/msbuild/issues/1603

Upvotes: 2

Related Questions