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

NuGet package build logic ignored under some obj customizations #2245

Open
rainersigwald opened this issue Jun 26, 2017 · 6 comments
Open

NuGet package build logic ignored under some obj customizations #2245

rainersigwald opened this issue Jun 26, 2017 · 6 comments
Labels

Comments

@rainersigwald
Copy link
Member

If you're in a situation where you want to customize the obj directory (IntermediateOutputPath) path, you may run into a situation where the build ignores packages' .props and .targets files.

This happens if you assign a value to IntermediateOutputPath after importing Microsoft.Common.props, which is easy to do, especially with Sdk imports.

<Project Sdk="something">
  <PropertyGroup>
    <!-- This is bad! -->
    <IntermediateOutputPath>SomeCustomValue</IntermediateOutputPath>
  </PropertyGroup>
</Project>

The reason this causes silent errors is that NuGet restore happens at the solution level. Restore asks each project for some information, and gets the final value of the obj directory, after the top-to-bottom evaluation of the project, so it gets the customized value. NuGet then generates .props and .targets files in that location.

When the actual build begins, Microsoft.Common.props attempts to import the generated file from the default obj location, because at the time of the import, the property hasn't been set to its custom value. No file is present in that location and the build silently continues, with no NuGet-package-delivered customizations.

Workaround

Customize the obj directory using Directory.Build.props, or another mechanism that sets BaseIntermediateOutputPath before the MSBuildProjectExtensionsPath in Microsoft.Common.props.

📝 Note: doing this means that you do not have access to very many properties that are set to defaults in the imported props. Be careful to use only built-in properties or constants, and not rely on things like $(AssemblyName).

@rainersigwald
Copy link
Member Author

Reported offline by @MikhailArkhipov -- thanks!

fyi @jeffkl, @emgarten

@emgarten
Copy link
Member

emgarten commented Jul 6, 2017

//cc @rohit21agrawal

@ghost
Copy link

ghost commented Mar 13, 2018

Just hit it myself, will this get fixed in the upcoming version of MSBuild? Thanks!

@jeffkl
Copy link
Contributor

jeffkl commented Mar 13, 2018

We're adding an error in common targets if you set BaseIntermediateOutputPath and a warning if you set MSBuildProjectExtensionsPath in the body of a project.

#3059

@huangjinshe
Copy link

@jeffkl Why? We need a custom address for "obj" folder, so we need to change it. Also Please don't put something in that folder, if you need put something in it, just give us another property for put an address for another place.

What is "obj" folder for? google tell us: The "obj" folder is used to store temporary object files and other files used in order to create the final binary during the compilation process. The "bin" folder is the output folder for complete binaries (assemblies).

So please don't cofuse about temporary files and permanent files. We need to separate it, I thought you guys gave us MSBuildProjectExtensionsPath for put some permanent files(at least will not change too frequently)

<PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <OutputPath>Y:\Cache\$(MSBuildProjectName)\$(Configuration)</OutputPath>
    <MSBuildProjectExtensionsPath>$(MSBuildThisFileDirectory)\..\Extentions</MSBuildProjectExtensionsPath>
    <BaseIntermediateOutputPath>Y:\Cache\$(MSBuildProjectName)\obj\$(Configuration)</BaseIntermediateOutputPath>
  </PropertyGroup>

But after that it told me that's wrong again....Don't know what you guys want to do....

@huangjinshe
Copy link

huangjinshe commented Mar 16, 2019

@jeffkl , After I removed MSBuildProjectExtensionsPath, it all going to right, obj folder still in the old place, but not always create some temporary files, those temporary files only create in the address of BaseIntermediateOutputPath. But only problems are that: Visual Studio will keep output an annoying messages about Directory.Build.props, and the obj folder included in the project in visual studio 2017.

@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants