我有一个库,用于使用的SDK。用于V10的SDK不同于V9.3,我还有x86/x64和SQL/HANA构建,这给了我8个排列,因此有8个包。
使用这些包的项目也将有8个构建。我希望设置项目文件和目标,以便为特定的配置和平台选择特定的包。我正在努力解决这个问题,但这是完全没有意义的。
目前,我的项目文件中有以下内容:
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v93SQL|x64' ">
<PackageReference Include="OchALCommon.v93SQLx64" Version="1.0.*" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v93SQL|x86' ">
<PackageReference Include="OchALCommon.v93SQLx86" Version="1.0.*" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v93HANA|x64' ">
<PackageReference Include="OchALCommon.v93HANAx64" Version="1.0.*" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v93HANA|x86' ">
<PackageReference Include="OchALCommon.v93HANAx86" Version="1.0.*" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v10SQL|x64' ">
<PackageReference Include="OchALCommon.v10SQLx64" Version="1.0.*" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v10SQL|x86' ">
<PackageReference Include="OchALCommon.v10SQLx86" Version="1.0.*" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v10HANA|x64' ">
<PackageReference Include="OchALCommon.v10HANAx64" Version="1.0.*" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'B1v10HANA|x86' ">
<PackageReference Include="OchALCommon.v10HANAx86" Version="1.0.*" />
</ItemGroup>Visual指示所有8个包和一个构建过程--每个包的依赖项--这似乎是错误的。我还在"Directory.Build.targets“文件中尝试了这段代码,该文件最初看起来很有效,但后来Visual停止响应目标文件中的更改(即使在重新启动之后)。
我们过去在程序集引用中一直使用这种引用,而且它似乎很有效,我不知道如何使PackageReference函数。有人知道如何在我的场景中最好地打包这个库吗?
在理想的世界中,我想以某种方式将我的64位和32位构建以及一些适当的目标存储在一个nuget包中,这样消费项目就可以获得正确的bitness和正确的子项目引用。目前,我无法解决如何做到这一点,也无法得到任何其他可行的方案。
再说一遍,有人知道怎么做这样的事吗?
谢谢。
发布于 2021-10-20 10:13:12
到目前为止,我已经能够通过对每个.targets使用单独的文件( ProjectReference )来解决这个问题,然后通过引用特定的.targets文件来确保项目中只包含那些包含参考信息的文件。
然后,我将.targets文件放入一个保护伞nupkg中,以选择我想要使用的实际有效载荷中的哪一个。整个安排如下:
我发布了8个有效载荷文件如下:
每个有效负载文件只包含一个标准的lib/net40 40文件夹,其中包含https://learn.microsoft.com/en-us/nuget/create-packages/creating-a-package页面中指定的库。
我的消费项目有4种配置:
然后,我有一个伞式项目"MyLibrary.Targets“,其中包含如下内容:
#构建/net40/MyLibrary.Targets.targets.目标.目标
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<Import Project="MyLibrary/$(Configuration).targets" />
</Project>#build/net40 40/MyLibrary/B1v10HANA.Target
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<ItemGroup>
<PackageReference Include="MyLibrary.v10HANA$(Platform)" Version="1.0.*" />
</ItemGroup>
</Project>#build/net40 40/MyLibrary/B1v10SQL.目标
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<ItemGroup>
<PackageReference Include="MyLibrary.v10SQL$(Platform)" Version="1.0.*" />
</ItemGroup>
</Project>#build/net40 40/MyLibrary/B1v93HANA.Target
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<ItemGroup>
<PackageReference Include="MyLibrary.v93HANA$(Platform)" Version="1.0.*" />
</ItemGroup>
</Project>#build/net40 40/MyLibrary/B1v93SQL.目标
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
<ItemGroup>
<PackageReference Include="MyLibrary.v93SQL$(Platform)" Version="1.0.*" />
</ItemGroup>
</Project>我还在这个文件夹中有目标文件,"Debug.targets“和"Release.targets”,它们在这些情况下使用我首选的默认库。
按照上面链接的微软指南,所有软件包的.nupec文件都是相当标准的。可以使用'nuget spec‘命令创建默认的nuspec文件,然后可以进行编辑。
我的函数包nuspec文件在“包/元数据/依赖项”中包含了内容,这些内容标识了所需的包:
<dependencies>
<group targetFramework=".NETFramework4.0">
<dependency id="CryptLib" version="*" />
<dependency id="SAPBusinessOneSDK.HANA" version="10.0.*" />
</group>
</dependencies>我的Selector包"MyLibrary.targets“没有依赖项,但是有一个文件部分' package / files ':
<files>
<file src="readme.txt" target="" />
<file src="build\**" target="build" />
</files>希望这能节省一些时间。
https://stackoverflow.com/questions/69631191
复制相似问题