-
-
Notifications
You must be signed in to change notification settings - Fork 83
MSBuild props/targets from NuGet package are not imported into a nanoFramework project #1544
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
MSBuild props/targets from NuGet package are not imported into a nanoFramework project #1544
Comments
I haven't tried it myself but I'm suspecting this is because our project extension (nfproj) differs from the standard one (csproj) and the Visual Studio tools can't handle it when processing the ad slash removal off the props and targets. Our project system doesn't support As you've mentioned, the work around is to use the infamous import PowerShell script. I personally don't like that approach very much because that's a security risk (that's one of the reasons for this being removed/replaced in the current .NET project system). I suggest that we wait for the reply on the question you've raised in Developer community portal before making a decision. Because, if this is a bug in the tools, we have nothing fix at our end (as I suspect it's the case). |
Yes, let's hope that I get a reaction from Microsoft. I hope they can tell what aspect of the nanoFramework project Visual Studio is using to prevent the addition/removal of imports. The NuGet code seems to work fine - I repurposed one of their unit tests and debugged it, and that code adds the imports conform spec. So I suspect that Visual Studio post-processes the XML produced by the NuGet code and then ignores the added imports. The reason I investigated a workaround is that this type of package is really very useful to add tools to a project, e.g., a test adapter, MSBuild task for version checking, debugging unit tests and more. There may be PRs in the near future that refer to this issue and propose to use the workaround while waiting two years (2022 to 2024 for icons, isn't it? ;-)) for Microsoft to implement a fix. |
It really depends on the traction it gets from the developer base. |
Haven't heard from Microsoft, but nanoFramework can provide a fix that should work for all regular projects. See nanoframework/nf-Visual-Studio-extension#887. |
Tool
Visual Studio extension
Description
If a NuGet package contains files
build\<package_id>.props
and/orbuild\<package_id>.targets
, the Visual Studio 2022 package manager is supposed to update the project file. If the type of project supportsPackageReference
, a package reference is added. If the project file is a .NET Framework-type MSBuild file (like the nanoFramework projects), anImport
element is added to import the .props and/or .targets file that points to the files in the location of the (unpacked) NuGet package.... but not for a nanoFramework project! All other files in a NuGet package are handled as expected, even other special file types (e.g., a NuGet package with only content files). It gets even weirder. The code of the NuGet client used by Visual Studio package managers can be found on github, and nothing in the code suggests that the imports are not supported for nanoFramework project files. That suggests that when Visual Studio saves the project file's XML as created by the package manager code (that seems to contain the imports), the imports are not properly saved but other changes are. I've asked Microsoft whether that is true and what the cause is, but that is still under investigation and may be a hard problem.
One possible cause is that one of the project (type) capabilities is required for the imports to work, and that capability is missing. I couldn't find one in the documentation, and without access to the Visual Studio source code it is hard to tell.
Even if this is fixed, it is not clear whether the fix will be applied to both Visual Studio 2019 and 2022.
There is a workaround: an install.ps1 can be added that add the imports to the nanoFramework project. The reverse (uninstall removes the imports) does not seem to work properly. I'm curious whether the core team would accept this workaround in future contributions.
How to reproduce
Required files are in this file: NuGetBuildpackage.zip
The zip file contains three packages:
BuildPackage.1.0.0.nupkg
that contains a .props and .targets file.BuildPackage_workaround.1.0.0.nupkg
that contains a .props and .targets file and workaround (install.ps1 and uninstall.ps1).ContentPackage.1.0.0.nupkg
that contains only content files.The zip file contains two projects:
RegularProject.Template
is a .NET Framework class library project with solutionTestProject.Template
is a nanoFramework class library project with solutionThe templates are configured that the three packages can easily been installed via the NuGet package manager in Visual Studio, without affecting any other NuGet package storage locations.
The issue can be demonstrated:
TestProject.Template
directory, open the solution in that directory and install theBuildPackage.1.0.0.nupkg
Expected behaviour
The expected situation can be viewed:
RegularProject.Template
directory, open the solution in that directory and install theBuildPackage.1.0.0.nupkg
Other project types behave as expected, e.g.,:
TestProject.Template
directory, open the solution in that directory and install theContentPackage.1.0.0.nupkg
As a demonstration of the workaround:
TestProject.Template
directory, open the solution in that directory and install theBuildPackage_workaround.1.0.0.nupkg
Screenshots
No response
Aditional context
All latest versions: Visual Studio 2022, nanoFramework extension.
Reported here NuGet/Home#1850.
The text was updated successfully, but these errors were encountered: