NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

.props and .targets from build folder in NuGet package not imported after package restore in VS #982

Closed rathole closed 6 years ago

rathole commented 9 years ago
Environment:

When the project is loaded at step 4, the NuGet package's .props and .target files do not exist so they are not imported into the project.

When the project is built at step 5, Visual Studio restores the NuGet package but the project is not reloaded, so the .props and .targets file are still not imported, which will cause the build to fail or otherwise behave improperly depending on what the .props and .targets file actually do.

Requested change:

Could the Visual Studio NuGet extension automatically reload relevant projects after a package restore?

emgarten commented 9 years ago

The projects should not need to be reloaded here. NuGet runs before MSBuild, if the files are on disk MSBuild will pick them up when it starts. Does reloading the project manually in VS actually fix the issue for you? Are you seeing the same issue when building from the command line with msbuild?

rathole commented 9 years ago

Thanks for responding. Indeed, reloading the project manually in VS fixes it. When building from command line with msbuild the problem does not occur, because then the package restore is done first before running msbuild.

emgarten commented 9 years ago

@rathole NuGet 2.8.6 was released this week, can you try with that version?

rathole commented 9 years ago

Done, same result.

A thought - instead of reloading the project(s) after package restore like I suggested, it might be better to actually do the package restore before VS loads the solution/projects. This would prevent the IntelliSense errors I now get when I open the solution in VS (which occur because referenced assemblies will be missing if the package is not restored yet).

rathole commented 9 years ago

Additional info: I can consistently reproduce this issue with VB projects, but C# and C++ projects don't seem to be affected. I have updated to scenario description above to reflect this.

niemyjski commented 7 years ago

Bare minimum it should be in the docs that the targets and props file name has to match the package id.. http://sushihangover.github.io/nuget-and-msbuild-targets/

emgarten commented 7 years ago

Bare minimum it should be in the docs that the targets and props file name has to match the package id..

The build folder conventions are documented here: https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#including-msbuild-props-and-targets-in-a-package

thebothead commented 6 years ago

I am having a similar issue, if not the same, with csharp in VS2015.

I am importing a props file (the imports are added correctly on package install). However, when building am not seeing the correct results. The props file I have points to a code analysis rule set file with style cop settings, and only after the project is reloaded are the rules actually applied correctly. Before reloading the project the default rule set is used for style cop.

props file

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">       
<PropertyGroup>       
<WarningLevel>4</WarningLevel>       
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>       
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>       
<RunCodeAnalysis>true</RunCodeAnalysis>       
<CodeAnalysisRuleSet>$(SolutionDir)packages\SE.DSP.Common.Rules.CodeAnalysis.1.0.0\SE.DSP.Common.Rules.CodeAnalysis.ruleset</CodeAnalysisRuleSet> 
</PropertyGroup>       
</Project>      

Also I notice that the warnings are not flagged as errors. So it appears none of the settings are honored until after a reload of the project.

emgarten commented 6 years ago

@thebothead there have been a lot of fixes around props/targets file reloading in VS 2017. I suggest updating to the latest version and trying your scenario there.

thebothead commented 6 years ago

@emgarten thanks, confirmed this is fixed in VS2017.

emgarten commented 6 years ago

Glad it is fixed for you @thebothead, thanks for checking! 🍰

pc-hansen commented 5 years ago

I have build a nuget package at published it to a nuget.server site. But when I try to use the package form the server the .targets file from build folder is not in the file. But if I use the package from a local folder it works as it should. How do I get it to work ?

If i look in the package in the folder on the server it looks ok.

fabsulous commented 2 years ago

I can still reproduce the problem with Visual Studio 2022 / NuGet Package Manager 6.1.0, for example with https://nuget.info/packages/OpenCvSharp4.runtime.win/4.0.0.20190108 - I can install, clean, close the solution, delete the package folder, reopen the solution, build with automatic restore and the folder "dll" will not be present in $(OutDir), however when I reload the solution after restoring and then build, the folder "dll" will be present.