Cannot use nuget package within the project - xamarin

Hi I have created a nuget package for my xamarin.iOS project. I have included the DLL which is generated from my Xamarin binding project. This is my .nuspec file
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>ABC.SDK</id>
<version>1.0.0.0</version>
<title>Title</title>
<authors>ABC</authors>
<owners/>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Your description</description>
<releaseNotes/>
<copyright>Your copyright notice</copyright>
<tags/>
<dependencies>
<dependency id=""/>
</dependencies>
<summary/>
</metadata>
<files>
<file src="D:\ABC\proj\BindingProject\UnityBinding\UnityBinding\bin\Release\ABCLibrary.dll" target="iOS\ABCLibrary.dll"/>
</files>
</package>
I installed this nuget package into my Xamarin project using local repository. My problem is it is not included in the project solution's package folder.
Also in the project.assets.json file, for my nuget package it has only this
"ABC.SDK/1.0.0": {
"type": "package"
},
What is the wrong I have done? Please help me.
Thanks

The target you are using is wrong. For Xamarin.iOS you should use lib/Xamarin.iOS10 and not iOS/ABCLibrary.dll.

Related

How to create my own custom nuget package for System.Data.SQLite to correctly include the interop dlls?

I want to create my own custom package for System.Data.SQLite. I have the all the dll's I need but I'm unsure how to structure it and create the nuspec for it.
Current folder structure of the dll's is this, whereabouts would I put the different interop dlls to have them copied correctly to the output and what do I need to add to the nuspec?
lib/net452
-> System.Data.SQLite.dll , System.Data.SQLite.Linq.dll, System.Data.SQLite.EF6.dll
Custom.SQLite.nuspec
Still have the default nuspec something like this atm
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Custom.SQLite.Name</id>
<version>1.0.0.0</version>
<authors>name</authors>
<owners>owner</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Desc</description>
<copyright>Copyright 2021</copyright>
</metadata>
</package>
SQLite.Interop.dll does not act as a lib assembly dll. That is not its role. And it should be a content file rather than a assembly dll. So it should not be packed as lib.
To create such custom nuget package, you should first pack System.Data.SQLite.dll, System.Data.SQLite.Linq.dll, System.Data.SQLite.EF6.dll as lib. See this document.
and then pack SQLite.Interop.dll as content.
Also, to make the content file be copied into the output folder of the main project when you install the nuget package, you have to use a <packages_id>.props or targets file to realize it.
1) create a file called <packages_id>.props into your class library project. And it should be the same name as your nuget package. In your side, it should be named as Custom.SQLite.Name.props. Otherwise, it will not work.
And then add these into the file:
<Project>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\content\x86\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="$(MSBuildThisFileDirectory)..\content\x64\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
2) use this nuspec file:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
<metadata minClientVersion="2.5">
<id>Custom.SQLite.Name</id>
<version>1.0.0.0</version>
<authors>name</authors>
<owners>owner</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Desc</description>
<copyright>Copyright 2021</copyright>
</metadata>
<files>
<file src="System.Data.SQLite.dll" target="lib\net452" />
<file src="System.Data.SQLite.EF6.dll" target="lib\net452" />
<file src="System.Data.SQLite.Linq.dll" target="lib\net452" />
<file src="xxx\x86\SQLite.Interop.dll" target="content\x86" />
<file src="xxx\x64\SQLite.Interop.dll" target="content\x64" />
<file src="Custom.SQLite.Name.props" target="build" />
</files>
</package>
3) rebuild your lib project and then use nuget pack to pack the new version.
Before you use this new version, please uninstall the old one and delete all cache files under C:\Users\xxx\.nuget\packages\Custom.SQLite.Name and <solution_folder>\packages\Custom.SQLite.Name.1.0.0. Then, reinstall the new version.

NetCore 3.1 Project reference converted to package reference when packing

I have netcore 3.1 Console application with a Package Reference and a Project Reference.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageId>MyPackageId</PackageId>
<Product>MyProduct</Product>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AssemblyName>MyAssemblyName</AssemblyName>
<Version>1.0.1</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Mono.Options" Version="6.6.0.161" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MyUtilityProject.csproj" />
</ItemGroup>
</Project>
I would expect the pack function to reference the compiled dll's from MyUtilityProject, but instead it looks up the version from MyUtilityProject.csproj and converts it into a package reference.
Here is the generated .nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>MyPackageId</id>
<version>1.0.1</version>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<dependencies>
<group targetFramework=".NETCoreApp3.1">
<dependency id="MyUtilityProject" version="2.13.0" exclude="Build,Analyzers" />
<dependency id="Mono.Options" version="6.6.0.161" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>
<files>
<file src=".\MyProduct\bin\Debug\netcoreapp3.1\MyProduct.runtimeconfig.json" target="lib\netcoreapp3.1\MyProduct.runtimeconfig.json" />
<file src=".\MyProduct\bin\Debug\netcoreapp3.1\MyProduct.dll" target="lib\netcoreapp3.1\MyProduct.dll" />
</files>
</package>
How do I convince the VS build job, that it should include the dll's and not reference the package?
The resolution to my problem was adding
<PackAsTool>true</PackAsTool>
to the project file.
I guess it was not quite clear from my question, that I was trying to build a tool, except for the fact that OutputType is exe.
This leads to the conclusion, that MicroSoft assumes that if you push a packet, all referenced projects are also pushed as packages.

Create nuget package and installing issues

I created a nuget package, all seems to be ok (no error message), when I install it from Package Manager Console, the dll is in XXX/lib/lib ... I don't know why there are two lib folder ??? I tried to change my nuspec with several solutions but I always had the same folder
<package>
<metadata>
<id>Telerik.Reporting.OpenXmlRendering</id>
<version>8.1.14.804</version>
<title>Telerik.Reporting.OpenXmlRendering</title>
<authors>XXXXX</authors>
<owners>XXXXX</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Assembly XXXX</description>
<copyright>Copyright XXXX</copyright>
<references></references>
<tags></tags>
</metadata>
<files>
<file src="*.dll" target=".\" />
</files>
</package>
I tried
<file src="*.dll" target="lib\net45" />
<file src="*.dll" target="lib\" />
<file src="*.dll" target="" />
And the installed always put the dll in :
C:\XXXXXX\packages\Telerik.Reporting.OpenXmlRendering.8.1.14.804\lib\lib
Do you have any ideas ?
Thanks

My nupkg is incompatible with my Unified API app

I've made a NuGet package that has a lib/Xamarin.iOS10 folder with a dll inside it.
I've created a test project (an iOS unified API Single View App) and I try to add my package but I get this response:
Could not install package 'mypackage 1.0'. You are trying to install
this package into a project that targets 'Xamarin.iOS,Version=v1.0',
but the package does not contain any assembly references or content
files that are compatible with that framework. For more information,
contact the package author.
Extracting the file, I can verify that my dll is present.
This is the nuspec file:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata minClientVersion="2.8">
<id>MyPackage</id>
<version>1.0</version>
<title>My Package</title>
<authors>Kristian</authors>
<owners>Kristian</owners>
<developmentDependency>true</developmentDependency>
<licenseUrl>http://www.opensource.org/licenses/mit-license.php</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Experiment Package</description>
<summary />
<language>en-US</language>
<tags></tags>
<dependencies>
<dependency id="Fody" version="1.29.3"/>
</dependencies>
</metadata>
<files>
<file src="../MyPackage.XamarinIOS/bin/iPhone/Release/MyPackage.dll" target="lib/Xamarin.iOS10/MyPackage.dll" />
</files>
</package>
Is there anything else I need to do? I am not using the new project.json format for my package.. I am using Xamarin Studio version 5.9.8.
Shouldn't that be:
target="lib/xamarinios10/MyPackage.dll"
Instead of your Xamarin.iOS10 path?

vsixmanifest for all: VS 2010, 2012 and 2013

I'm using VSIX Manifest Designer under VS2013. I've added Microsoft.VisualStudio.Pro product identifier and [10.0,13.0) version range to install targets. Despite that fact, I still don't see my VS2010 Professional as an available installation target:
The source.extension.vsixmanifest file content is shown below:
<?xml version="1.0" encoding="utf-8"?>
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
<Metadata>
<Identity Id="ae98c9e5-8e14-4c92-b45a-c4fd24a49123" Version="1.0" Language="en-US" Publisher="whosoever" />
<DisplayName>MyExtension</DisplayName>
<Description xml:space="preserve">whosoever</Description>
<MoreInfo>http://www.myextension.com</MoreInfo>
<License>LICENSE.txt</License>
<Icon>icon.png</Icon>
<PreviewImage>screenshot.png</PreviewImage>
</Metadata>
<Installation InstalledByMsi="false">
<InstallationTarget Version="[10.0,13.0)" Id="Microsoft.VisualStudio.Pro" />
</Installation>
<Dependencies>
<Dependency Id="Microsoft.Framework.NDP" DisplayName="Microsoft .NET Framework" d:Source="Manual" Version="4.5" />
<Dependency Id="Microsoft.VisualStudio.MPF.11.0" DisplayName="Visual Studio MPF 11.0" d:Source="Installed" Version="11.0" />
</Dependencies>
<Assets>
<Asset Type="Microsoft.VisualStudio.VsPackage" d:Source="Project" d:ProjectName="%CurrentProject%" Path="|%CurrentProject%;PkgdefProjectOutputGroup|" />
</Assets>
</PackageManifest>
What should be changed to enable installation of this extension to VS2010, 2012 and 2013?
What you have is the version 2 VSIX manifest, which is not compatible with Visual Studio 2010. Later Visual Studio versions respect version 1 of the manifest, so in order to support all 3 Visual Studio versions with a single manifest, you'll have to convert it to v1.0 manually (and make sure NOT to edit it with VS2012+, otherwise it will be converted back to v2.0).
Something like this:
<?xml version="1.0" encoding="utf-8"?>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
<Identifier Id="ae98c9e5-8e14-4c92-b45a-c4fd24a49123">
<Name>MyExtension</Name>
<Author>whosoever</Author>
<Version>1.0</Version>
<Description xml:space="preserve">Your decription.</Description>
<Locale>1033</Locale>
<SupportedProducts>
<VisualStudio Version="10.0">
<Edition>Pro</Edition>
</VisualStudio>
<VisualStudio Version="11.0">
<Edition>Pro</Edition>
</VisualStudio>
<VisualStudio Version="12.0">
<Edition>Pro</Edition>
</VisualStudio>
</SupportedProducts>
<SupportedFrameworkRuntimeEdition MinVersion="4.0" />
</Identifier>
<Content>
<VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage>
<MefComponent>|%CurrentProject%|</MefComponent>
</Content>
</Vsix>
You don't have to specify all product editions (called SKUs), Pro is enough, if, say, Ultimate is installed, it will be displayed instead.
It is working pretty good (Thanks a lot to Igal), if the VSIX is developed in VS 2012, and installed in VS 2015. However, the reverse is not working (means developed in VS 2015 and try to install in VS 2012)
After analyzed Activitylog .xml, i found a work around
Could not load file or assembly 'Microsoft.VisualStudio.Shell.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.
Workaround I did
Remove VisualStudio.Shell.14.0 and Install VisualStudio.Shell.11.0 using Package manager console (Install-Package VSSDK.Shell.11), and installed in VS 2012. Now Working as expected

Resources