构建 csproj 时包含 NuGet 实用程序包
我需要使用包含我的项目实用程序的 NuGet 包。它包含多个二进制文件(EXE 和 DLL)。
我已成功将其添加到我的项目中,但我怀疑 nupkg 的格式不正确,因为如果不手动指向本地 NuGet 缓存中的包,我就无法在项目中使用它的任何 DLL 或 EXE。编译时,它的任何资源都不会添加到输出中(我认为这是因为我的代码中没有引用任何内容)。
我想创建一个包装器项目来调用二进制文件,但我也希望其他项目开发人员能够在不调整目录变量的情况下编译解决方案。理想情况下,我可以将 csproj 配置为直接从本地包缓存中提取位。我认为通过在 Visual Studio 中将 Generate Path Property
值设置为 Yes
可以实现这一点,但是当我尝试使用 时找不到该变量。 csproj 文件中包含/>
语句。
我问的可能吗?也就是说,引用我的 csproj 中的 NuGet 包位以确保二进制文件被删除在编译输出中?我可以使用 Path 属性来执行此操作,还是可以在不直接将包的二进制文件提交到我的项目中的情况下执行其他操作?
(我意识到我需要与开发人员合作来解决他们的软件包存在的任何问题,但我目前没有直接影响力,所以这是我目前能做的最好的事情)。
I need to use a NuGet package containing a utility for my project. It contains several binaries (EXEs and DLLs).
I've added it to my project successfully but I suspect the nupkg isn't formed correctly because I cannot use any of its DLLs or EXEs in my project without manually pointing to the package in my local NuGet cache. When compiling, none of its resources are added to the output (I assume this is because nothing is referenced in my code).
I'd like to create a wrapper project to call the binaries but I'd also like other project devs to be able to compile the solution without adjusting directory variables. Ideally, I could configure the csproj to pull in the bits directly from the local package cache. I think this would be possible by setting the Generate Path Property
value to Yes
in Visual Studio, but the variable cannot be found when I attempt to use an <Include/>
statement in the csproj file.
Is what I'm asking possible? Namely, reference the NuGet package bits within my csproj to ensure the binaries are dropped in the compilation output? Can I do this with the Path Property, or is there something else I can do without directly committing the package's binaries into my project?
(I realize I need to work with the developer to fix whatever issue they have with their package, but I have no direct influence at the moment so this is the best I can do at the moment).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现了这一点,主要是由于误解了一些不同标签和属性的用途。
为了达到预期的效果,我执行了以下操作:
其中
{PackageId}
是 NuGet 包的名称(此步骤需要通过解决方案资源管理器在包属性中将“生成路径属性”设置为“是” ),并且{NameOfSolutionDirectory}
是解决方案中我想用来包含这些位的文件夹的名称,如果您像我一样关心保持项目的组织性。替换这些值时应排除{}
。如果您想要将范围限制到包内容中的特定目录,请在
Include
属性中执行此操作。如果您想要包含该目录中的所有 文件,则**
是必需的,否则您可以通过扩展名或任何您想要的其他模式来确定范围。I figured this out, mostly due to misunderstanding how some of the different tags and attributes are meant to be used.
To achieve the desired effect, I did the following:
Where
{PackageId}
is the name of the NuGet package (this step requires setting 'Generate Path Property' to 'Yes' in the package properties via Solution Explorer), and{NameOfSolutionDirectory}
is the name of a folder within the solution I'd like to use for containing those bits, if you're as concerned about keeping the project as organized as I am. The{}
should be excluded when replacing these values.If you want to scope to a specific directory within the package contents, do it within the
Include
attribute. The**
is necessary if you want to include all files within that directory, or else you can scope by extension or whatever additional pattern you'd like.