我試圖通過在Visual Basic項目文件中搜索所有導入並對其進行逆向工程後,使其工作。我在其中一個導入的目標中找到了這個。
<!-- Import design time targets for Roslyn Project System. These are only available if Visual Studio is installed. -->
<!-- Import design time targets before the common targets, which import targets from Nuget. -->
<PropertyGroup>
<VisualBasicDesignTimeTargetsPath Condition="'$(VisualBasicDesignTimeTargetsPath)'==''">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\Managed\Microsoft.VisualBasic.DesignTime.targets</VisualBasicDesignTimeTargetsPath>
</PropertyGroup>
<Import Project="$(VisualBasicDesignTimeTargetsPath)" Condition="'$(VisualBasicDesignTimeTargetsPath)' != '' and Exists('$(VisualBasicDesignTimeTargetsPath)')" />
搜索導入的文件$(MSBuildExtensionsPath)\微軟\ VisualStudio的\管理\ Microsoft.Managed.DesignTime.targets後,我發現下面的代碼。
<ProjectCapability Include="
AssemblyReferences;
COMReferences;
ProjectReferences;
PackageReferences;
SharedProjectReferences;
OutputGroups;
AllTargetOutputGroups;
VisualStudioWellKnownOutputGroups;
SingleFileGenerators;
DeclaredSourceItems;
UserSourceItems;" />
將項目能力添加到我的項目目標文件中,NuGet軟件包工作正常!我不確定是否所有這些都是需要的,但我無法縮小範圍,行爲對我的應用來說似乎很好。
這裏列出了某些人在搜索時的一些功能。 https://github.com/Microsoft/VSProjectSystem/blob/master/doc/overview/project_capabilities.md
編輯
只是用了一段時間的解決方案後,工作這個問題跟進。有關功能的更多信息可以在這裏找到: https://docs.microsoft.com/en-us/nuget/visual-studio-extensibility/project-system-support
這將啓用VS中的NuGet包管理器,但安裝將失敗。解決方案需要實施許多類才能實現其功能。
VS之外有點簡單,可以與NuGet客戶端EXE一起使用,但是對於自定義項目擴展需要做一些小改動。如果你下載了NuGet源代碼,你可以看到代碼只是用一個硬編碼的擴展列表來更新項目文件。因此,如果您在解決方案或packages.config文件上進行更新或恢復,則需要將擴展名添加到列表中。這樣它就會找到你的項目文件並對其執行操作。
您很可能需要修改NuGet源代碼以啓用此功能。 [MSBuildNuGetProjectSystemFactory類](https://github.com/NuGet/NuGet.Client/blob/7985322db49b11340ad4bf0c73247c9bd0096621/src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/ProjectSystems/MSBuildNuGetProjectSystemFactory.cs#L22-L28)顯示了一些項目系統在NuGet中支持。 –