Migrate to PackageReference Missing Nuget Build Failure - xamarin.forms

I have a Xamarin Forms Project - the Android project targets API 28 (Pie) and uses packages.config for the nuget references. All of the packages have a targetFramework="monoandroid90". The project compiles and runs correctly.
I want to migrate to using PackageReference, so I use the Migrate packages.config to PackageReference option.
After this completes I try to build the project and receive an error regarding a missing package:
Xamarin.Android.Support.Annotations.28.0.0.1
Looking in the packages folder, I can see that none of the Xamarin.Android.Support packages have been downloaded and I can't get them to download - even by reinstalling the package.
I also noticed that the csproj file reference monoandroid81 for all the nugets, even though the packages.config used monoandroid90
Has anyone had a similar difficulty after migrating?

Related

New project xamarin.form prism Error NETSDK1004 - Prism 2.2.1

when generating a new project xamarin.form prism I get this error when running. With the previous version 2.1.7 it worked for me OK.
It does not allow me to open the Nuget Package since it also gives an error.
Any recommendation?
I saw the 2 posts of this error but they do not apply to me.
Error NETSDK1004 Assets file 'C:\Empresas\Job_Facu\Job\Job.Prism\Job.Prism\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. Job.Prism C:\Program Files\dotnet\sdk\3.1.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 234
The error tells you what to do. Run a NuGet restore. Visual Studio should help you do this automatically. Note that if this occurred after updating dependencies sometimes Visual Studio gets confused and it's best to close Visual Studio and reopen it. This usually gets it to refresh itself so you get the updated package restore.
If that's not working for you, you can download the latest nuget.exe and from the command line navigate to the solution directory and execute the command {path to nuget.exe} restore.
When NuGet performs a restore it generates the project.assets.json file in the obj folder of each project it has restored. This in turn provides MSBuild with the reference information it needs to properly reference your dependencies like Prism and Xamarin.Forms.
I have recently ran into similar issue as well, seemingly out of the blue. I believe upgrading my build machine to the latest VS version (VS for Mac 8.10.4 (build 11))
NETSDK1004: */project.assets.json' not found. Run a NuGet package restore to generate this file.
To fix, I had to run Nuget Restore twice. Once for the shared project directory and once for the iOS project.
If I run the restore just for the Shared/(main.sln file) project directory I get the error.
If I run the restore for the iOS project the build passes but IPA file isn't created.
Need to run both.
Modules used for CI/CD build in Azure Devops Pipeline

How to ignore dependencies for .NET Core during NuGet packaging?

I have my own NuGet packages located on a disk (local Nuget). I'm trying to not add the same DLL multiple times and get in a scenario like the image attached
I have tried the following code during packing but doesn't work
dotnet pack PathtoSolution\SystemCore.Services.Data --no-dependencies --output "G:\NuGetPackages"
However, during restoration to another project, the dependency comes back.
Is there a way to not include dependencies during the packing process or is ignoring at installation time my only option?
You can add to your PackageReference PrivateAssets="all" - however this has some undesirable effects as well as you won't be able to access the types defined in those assemblies outside of your nuget package. If that's ok with you, it would work.

VS for Mac unable to add .NET Standard NuGet

I have encountered a weird behavior with VS for Mac. This is how I repro it:
Built a .NET Standard 2.0 NuGet package using VS2017. Package is called "MobileApps.Auth 1.0.0"
Pushed the NuGet to our company NuGet server
Switched over to the Mac and launched VS
On the Mac; Built a Xamarin Forms app (shared project is also .NET Standard 2.0)
Added reference to the .NET Standard 2.0 NuGet
ERROR:
Package MobileApps.Auth 1.0.0 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package MobileApps.Auth 1.0.0 supports:
- monoandroid81 (MonoAndroid,Version=v8.1)
- xamarinios10 (Xamarin.iOS,Version=v1.0)
I have zero clues as to why the NuGet would support monodroid81 and xamarinios10. It's a .NET Standard 2.0 library that reference Xamarin.Forms.
If I instead remain on the PC and run steps 4 and 5 in Visual Studio 2017 all is peachy.
This smells like a bug in VS for Mac. Has anyone else seen this?
Overall, having spent a few days building NuGet packages, based on .NET Standard 2.0, both on the Mac and PC I get the overall feeling this doesn't really work on the Mac. The reason I built the NuGet on VS2017 is because NuGet packs built on VS for Mac includes all kinds of facades that causes msbuild to fail due to conflicts (same identifiers found in multiple referenced assemblies).
[EDIT 1]
This is the NuGet layout when package built on VS4M:
_rels (empty folder)
[Content_Types].xml
lib
netstandard2.0
MobileApps.Auth.dll (my lib)
(+ 113 other dlls)
MobileApps.Auth.nuspec
package
services
metadata
core-properties
5bd1f861cd8a425f854c073a4a5f3e0e.psmdcp
And this is the NuGet layout when built on VS2017:
_rels
.rels
[Content_Types].xml
lib
netstandard2.0
MobileApps.Auth.dll (my lib)
MobileApps.Auth.nuspec
package
services
metadata
core-properties
5bd1f861cd8a425f854c073a4a5f3e0e.psmdcp
The difference is that VS4M includes 113 extra dlls in the netstandard2.0 folder while VS2017 doesn't. How can I control that?
[EDIT 2]
This is the .nuspec from within the .nupkg, built with VS4M:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>MobileApps.Auth</id>
<version>0.1.1</version>
<title></title>
<authors>Jonas Rembratt</authors>
<owners>Jonas Rembratt</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>bla bla</description>
<summary></summary>
<releaseNotes></releaseNotes>
<copyright></copyright>
<language></language>
<dependencies>
<group targetFramework=".NETStandard2.0">
<dependency id="Xamarin.Forms" version="3.1.0.697729" />
<dependency id="System.ValueTuple" version="4.5.0" />
</group>
</dependencies>
</metadata>
</package>
Ok, here's the latest outcome from my experiments with NuGet/VS4M/VS2017. One problem seemed to be that VS4M included 113 libs in the NuGet package so I wanted to see if that was the problem or not. I first tried to simply renamed the .nupkg file into .nupkg.zip on the Mac, then unpack it, then remove the .nupkg, then remove the 113 libs in lib/netstandard20 leaving only my own dll in there. I then simply compressed the folder again into "MobileApps.Auth.nupkg.zip" but it seems Finder won't take kindly to then simply removing the ".zip" suffix. So, I simply moved the .zip over to Windows and removed the ".zip" suffix there before moving it back to MacOS. In the end I'm left with a .nupkg that in essence looks just like the one I generated with VS2017 (see OP), that is a package that contains only my own .dll file.
This works.
So, the problem now is that:
This leaves me with having to go through a tedious process of manually removing all unecessary .dll files from my NuGet package whenever I re-generate it. Is there really no way to configure the 'nuget' build to exclude these libs in the first place, like VS2017 does?
Why didn't it work when I built the .nupkg file on VS2017 and then tried to use it with my projects in VS4M?

VIsual Studio 2017 NuGet package installs well but is not recognized

I have Solution A which has a .NET Core 1.1 class library project. In the Package properties I filled all NuGet fields and selected to create the NuGet upon successful build. This project builds just fine and the NUPKG is created. BTW How can I automatically copy the generated NUPKG to a local directory (my own repository)?
Then I have Solution B which is an ASP.NET Core 1.1 web application. In it I browse to my local repository (where I have manually copied the NUPKG built by Solution A) and install my SolutionA.MyPackage into the web application. VS.2017 says it was successful at installing it. I see it listed in the project's NuGet dependencies.
However, when I try to use ANY of the objects defined in that NuGet package I get a red highlight saying it is not found as if there was no NuGet or assembly reference to that DLL but there is!
What is causing this Visual Studio generated Nuget package to be installed and yet act as if it has not even been referenced?
UPDATE - CSPROJ TARGET
As for copying to my local repository, I added this to CSPROJ but it was not working (somebody had suggested it as I put it). I finally figured out why it did not work, the ItemGroup must be inside the Task.
<Target Name="CopyPackage" AfterTargets="GenerateNuspec">
<ItemGroup>
<MyPackageFiles Include="bin\Release\PackageId.*.nupkg" />
</ItemGroup>
<Copy SourceFiles="#(MyPackageFiles)" DestinationFolder="D:\My Repository\MyNugget\Publish" />
</Target>
UPDATE NuGet Inspection
I opened the NUPKG with NuGet Package Explorer and it shows this more or less:
content\
Properties\
launchSettings.json
Views\
Shared\
rest of my stuff here
contentFiles\
any\
netcoreapp1.1\
Properties\
launchSettings.json
Views\
Shared\
rest of my stuff here
lib\
netcoreapp1.1 (.NEtCoreApp, Version=v1.1)
MyPackage.dll
UPDATE 3
Since NuGet seems to have stopped working (used to work well earlier) I opted for using an Assembly Reference rather than a NuGet (for now). In this situation something odd happens, when coding I can reference ALL the objects in the referenced assembly (former NuGet) and therefore no compilation errors on the main project BUT when I then run the web application I get an internal error because it says
FileNotFoundException: Could not load file or assembly
'MyPackage, Version=0.0.3.0, Culture=neutral, PublicKeyToken=null'.
The system cannot find the file specified.
Unknown location
Which is strange because in the Solution Explorer I see the assembly reference and when I click on it (main application) I can navigate to all the objects that I have defined in that assembly. Why it cannot find it anymore?
It is working again (as it was before!). Today I could open the solutions but when I tried to download an extension (Tools | Extensions) I got an error message about an Access Denied or something like that. It has happened before since I installed to VS.2017.
Of all the Visual Studios I have used since 2002 this has been the most unstable! (and I have update 15.2).
When I saw this error happening again I knew how to get rid of it and thought, "hey, maybe that is what is keeping the NuGet package to be installed but not found or the problem with a direct assembly reference".
So I went to my C:\Users\AppData\USER\Local\Microsoft\VisualStudio\15.2* folder and removed it completely.
After that I the ACCESS DENIED issue went away with the side effect that I had to reinstall all extensions again. I attempted again to install my own NuGet, it did so successfully and as expected (was not happening during the long glitch) the objects were found and the web application worked again.

NuGet packages not found after sync from GitHub

We (me and three other people) will make an ASP.NET MVC application and use GitHub for version control. We've added some NuGet packages like Unity.MVC5.
Person one has commit and sync the project to the master branch. He's got no problems. The other three people sync the branch but they got problems with the NuGet libaries. See errors below:
Error: This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props.
Error: Metadata file D:\...\MarkeOnlineWebsite\MarkeOnline.Website\bin\MarkeOnline.Website.dll could not be found
Warning: The referenced component ... could not be found.
Update: I've also added this .gitignore file.
How could we solve this problem?

Resources