The workaround from #760 (setting the BaseIntermediateOutputPath
property) does not work out for me in a project, where I reference a NuGet package with an MSBuild .targets with adds an assembly references. The concerned package (root) is JetBrains.ReSharper.SDK
.
Repro sample:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<!-- Doesn't work (see Class.cs): -->
<BaseIntermediateOutputPath>obj\XXX\</BaseIntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="JetBrains.ReSharper.SDK" Version="2016.3.20170126.124206" />
</ItemGroup>
</Project>
```C#
using static System.Console;
public class Class
{
public Class()
{
// Works fine:
WriteLine(typeof(JetBrains.Annotations.NotNullAttribute));
// Resolve error (type contained in assembly `JetBrains.Platform.Ide`)
// when using the overridden "BaseIntermediateOutputPath":
WriteLine(typeof(JetBrains.IDE.IEditorManager));
// The difference between the types:
//
// `NotNullAttribute` comes from the package `JetBrains.Annotations`
// (just an assembly within the "lib" dir)
// `IEditorManager` comes from the package `JetBrains.Platform.Core.Ide`
// with a "build" dir and the assembly reference comes from the .targets file in there
}
}
```
Note that the BaseIntermediateOutputPath
workaround worked fine with _non .NET Core projects_ (see ImplicitNullability.Plugin.R20163.csproj).
See #803 and https://github.com/Microsoft/msbuild/issues/1603.
The fix is to use Sdk
imports in the body of the project instead of the Sdk
attribute on the Project
element. Then set the BaseIntermediateOutputPath
before the initial .props are imported:
<Project>
<PropertyGroup>
<BaseIntermediateOutputPath>obj\XXX\</BaseIntermediateOutputPath>
</PropertyGroup>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<!-- Body of project -->
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</Project>
Alternatively, you can also set the BaseIntermediateOutputPath
property in a Directory.Build.props file as described in the issues I linked.
@dsplaisted: Thanks. This workaround fixed my problem.
Importing the SDK after specifying BaseIntermediateOutputPath
does not appear to work on Visual Studio for Mac. The IDE complains "Unknown solution item type" if I don't populate the SDK attribute in the Project
element.
Most helpful comment
See #803 and https://github.com/Microsoft/msbuild/issues/1603.
The fix is to use
Sdk
imports in the body of the project instead of theSdk
attribute on theProject
element. Then set theBaseIntermediateOutputPath
before the initial .props are imported:Alternatively, you can also set the
BaseIntermediateOutputPath
property in a Directory.Build.props file as described in the issues I linked.