[英]Nuget packaging in VS2017 csproj project
I have following project structure with 3 Nuget dependencies: 我有以下3 Nuget依赖项的项目结构:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;net46</TargetFrameworks>
...
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.9.0" />
<PackageReference Include="Selenium.WebDriver" Version="3.7.0" />
<PackageReference Include="SpecFlow.CustomPlugin" Version="2.2.1" />
</ItemGroup>
</Project>
It's really cool that VS2017 allows creating NuGet packages out of the box. VS2017允许开箱即用地创建NuGet包,这真的很酷。
But what can do if I want to include custom NuGet references and don't wanna include references I use now? 但是,如果我想包括自定义的NuGet引用并且不想包含我现在使用的引用,该怎么办?
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...
<dependencies>
<dependency id="SpecFlow" version="2.2.0" />
<dependency id="NUnit" version="3.0.0" />
<dependency id="Autofac" version="[3.3.0,3.5.2]" />
<dependency id="Autofac.Configuration" version="[3.3.0]" />
<dependency id="Selenium.WebDriver" version="3.0.0" />
</dependencies>
</metadata>
</package>
I this case I need to have Autofac with my lib but I don't need it to build my lib. 在这种情况下,我需要在我的库中安装Autofac ,但不需要它来构建我的库。 Or I don't need SpecFlow.CustomPlugin with all dependencies in project which will use my lib but it needs have one to build itself. 或者我不需要SpecFlow.CustomPlugin以及项目中的所有依赖项,而这些依赖项将使用我的lib,但是它需要自己来构建。
I think there is a way to include NuSpec file path to new csproj but I think all csproj PropertyGroup fields won't be used. 我认为有办法将NuSpec文件路径包括到新的csproj中,但我认为不会使用所有csproj PropertyGroup字段。
Any suggestions? 有什么建议么? Thanks 谢谢
You should use ExcludeAsset property following official documentation 您应该按照官方文档使用ExcludeAsset属性
https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files https://docs.microsoft.com/zh-cn/nuget/consume-packages/package-references-in-project-files
I modified the exemple in doc to match with your needs. 我修改了doc中的示例以符合您的需求。 You can change the ExcludeAssets
property if my change is not correct. 如果我的更改不正确,则可以更改ExcludeAssets
属性。
<ItemGroup>
<!-- ... -->
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0">
<ExcludeAssets>build</ExcludeAssets>
</PackageReference>
<!-- ... -->
</ItemGroup>
EDIT : 编辑:
I think you can try something like : 我认为您可以尝试类似的方法:
<PackageReference Include="Autofac" Version="3.5.2">
<ExcludeAssets>build</ExcludeAssets>
</PackageReference>
<PackageReference Include="Autofac.Configuration" Version="3.3.0">
<ExcludeAssets>build</ExcludeAssets>
</PackageReference>
If I well understand the documentation, this will exclude Props and targets in the build folder that are used to create by nuget package to create the dependencies 如果我能很好地理解文档,这将排除nuget包用于创建依赖项的build文件夹中的Props和目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.