简体   繁体   English

构建csproj时包含NuGet Utility Package

[英]Include NuGet Utility Package when building csproj

I need to use a NuGet package containing a utility for my project.我需要为我的项目使用包含实用程序的 NuGet package。 It contains several binaries (EXEs and DLLs).它包含几个二进制文件(EXE 和 DLL)。

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.我已经成功地将它添加到我的项目中,但我怀疑 nupkg 的格式不正确,因为如果不手动指向本地 NuGet 缓存中的 package,我就无法在我的项目中使用它的任何 DLL 或 EXE。 When compiling, none of its resources are added to the output (I assume this is because nothing is referenced in my code).编译时,它的任何资源都不会添加到 output(我假设这是因为我的代码中没有引用任何内容)。

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.理想情况下,我可以将 csproj 配置为直接从本地 package 缓存中提取位。 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.我认为这可以通过在 Visual Studio 中将Generate Path Property值设置为Yes来实现,但是当我尝试在 csproj 文件中使用<Include/>语句时找不到该变量。

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?即,在我的 csproj 中引用 NuGet package 位以确保二进制文件在编译中被删除 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?我可以使用 Path 属性来执行此操作,还是可以在不直接将包的二进制文件提交到我的项目中的情况下执行其他操作?

(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). (我意识到我需要与开发人员合作解决他们的 package 的任何问题,但我目前没有直接影响,所以这是我目前能做的最好的事情)。

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:为了达到预期的效果,我做了以下事情:

  <ItemGroup>
    <Content Include="$(Pkg{PackageId})\**">
      <Link>{NameOfSolutionDirectory}\%(RecursiveDir)%(Filename)%(Extension)</Link>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

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.其中{PackageId}是 NuGet package 的名称(此步骤需要通过解决方案资源管理器在 package 属性中将“生成路径属性”设置为“是”), {NameOfSolutionDirectory}是解决方案中文件夹的名称如果您像我一样担心保持项目井井有条,则喜欢使用它来包含这些位。 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.如果要将 scope 到 package 内容中的特定目录,请在Include属性中执行。 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.如果您想包含该目录中的所有文件,则**是必需的,否则您可以通过扩展名或任何您想要的其他模式来 scope。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当 .csproj 被称为 Nuget 包时的 FileNotFoundException - FileNotFoundException when the .csproj is referred as Nuget package Require.csproj nuget 包在构建解决方案时存在 - Require .csproj nuget packages to exist when building solution 如何在 .csproj 中引用 NuGet 包 - How to reference NuGet package in .csproj 如何在我的新 CSPROJ 类库中包含带有本机 dll 的 NuGet 包? - How can I include a NuGet package with native dlls in my new CSPROJ Class Library? 在构建 NuGet 包时,VS 将 csproj 文件中的元素伪装成<deterministic>和<embeduntrackedsources>不存在</embeduntrackedsources></deterministic> - When building NuGet packages, VS pretends elements in the csproj file like <Deterministic> and <EmbedUntrackedSources> don't exist MSBuild nuget 包:要添加到 .csproj 文件中的内容? - MSBuild nuget package: what to add to .csproj file? 指定要添加到 .csproj 文件中的 nuget 包的文件 - Specifying files to add to a nuget package in .csproj file 在Visual Studio中构建项目时如何安装Nuget包 - How install Nuget package when building project in Visual Studio 使用 Nuget package 的 ProjectReference 在构建时不包括在内 - ProjectReference which consumes a Nuget package isn't included when building 如何在构建NuGet包时向函数添加文档 - How to add documentation to a function when building a NuGet package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM