Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the BaseIntermediateOutputPath doesn't work with assembly references from .targets files #980

Closed
ulrichb opened this issue Mar 11, 2017 · 3 comments

Comments

@ulrichb
Copy link

ulrichb commented Mar 11, 2017

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>
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).

@dsplaisted
Copy link
Member

dsplaisted commented Mar 12, 2017

See #803 and dotnet/msbuild#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.

@ulrichb
Copy link
Author

ulrichb commented Mar 12, 2017

@dsplaisted: Thanks. This workaround fixed my problem.

@ulrichb ulrichb changed the title Changing the BaseIntermediateOutputPath doesn't with assembly references from .targets files Changing the BaseIntermediateOutputPath doesn't work with assembly references from .targets files Mar 12, 2017
@RotsiserMho
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants