UWP - Class librairies and PRI file generation - c#

In my UWP solution, I have a ClassLibrary1 project (with a BlankPage1.xaml) and a ClassLibrary2 project that references the ClassLibrary1 project (with a BlankPage2.xaml).
I'm doing 2 NuGet packages (one for ClassLibrary1 and another for the ClassLibrary2).
In an UWP app, I added the ClassLibrary2 NuGet package. But, when I compile this app, I get these compilation errors:
Error: Could not copy the file "C:\Users\xxx\.nuget\packages\classlibrary2\1.0.0\lib\uap10.0.16299\ClassLibrary1\BlankPage1.xbf" because it was not found.
Error: Could not copy the file "C:\Users\xxx\.nuget\packages\classlibrary2\1.0.0\lib\uap10.0.16299\ClassLibrary1\BlankPage1.xaml" because it was not found.
Error: Could not copy the file "C:\Users\xxx\.nuget\packages\classlibrary2\1.0.0\lib\uap10.0.16299\ClassLibrary1\ClassLibrary1.xr.xml" because it was not found.
I noticed that the ClassLibrary2.pri file includes these 3 files and it shouldn't because they are included in the ClassLibrary1 NuGet package.
How can I indicate to not include these files in the ClassLibrary2.pri ?
This is a sample project that reproduces the problem : https://github.com/kakone/PriGeneration/

I found a workaround by copying a custom filtered.layout.resfiles file to the obj folder before the MSBuild target named _GenerateProjectPriFileCore.
I added these lines in my .csproj :
<Target Name="CustomPriFileGeneration" BeforeTargets="_GenerateProjectPriFileCore" Condition=" '$(Configuration)'=='Release' ">
<Copy SourceFiles="$(ProjectDir)\filtered.layout.resfiles" DestinationFolder="$(BaseIntermediateOutputPath)\$(Configuration)\$(TargetFramework)" />
</Target>
and a filtered.layout.resfiles file in my project :
ClassLibrary2\BlankPage2.xaml
ClassLibrary2\ClassLibrary2.xr.xml

Related

Could not load file or assembly Microsoft.Data.SqlClient, Version=5.0.0.0

Facing following issue after deploying app to azure app service:
Unhandled exception. System.IO.FileNotFoundException: Could not load
file or assembly 'Microsoft.Data.SqlClient, Version=5.0.0.0,
Culture=neutral, PublicKeyToken=***********'. The system cannot find
the file specified.
Locally everything works as fine.
Microsoft.Data.SqlClient presented in site/wwwroot
Runtime Stack: Dotnetcore - 6.0
Main app and all class libs on .net6
Server Operating System: Linux
Microsoft.Data.SqlClient presented as reference from Microsoft.EntityFrameworkCore.SqlServer (v.7.0.2)
Tried different kinds of Nuget Packages versions - still have same issue
Tried to install Microsoft.Data.SqlClient (latest version & 5.0.0.0) directly into projects - still the same
The solution for us was to:
Locate the actual DLL file (Microsoft.Data.SqlClient.dll) on the developer's desktop filesystem (easy to find; once you're referenced it using NuGet it gets copied to multiple places)
Add it to the web project (we placed it right in the root)
Mark it (via Properties tool window) as Copy Always
Step 3 results in our .csproj file looks like this:
<ItemGroup>
<None Update="Microsoft.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

Cannot add package reference

I'm building a xamarin.ios app in VS mac. I'm trying to add a certain package, but when I try to add it I get this error
jon#jons-MacBook-Pro-2 helloworld % dotnet add package Ditto
/Users/jon/Desktop/hello-world/helloworld/helloworld/helloworld.csproj(140,5): error MSB4019: The imported project "/usr/local/share/dotnet/sdk/6.0.300/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/local/share/dotnet/sdk/6.0.300//Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.
Unable to create dependency graph file for project '/Users/jon/Desktop/hello-world/helloworld/helloworld/helloworld.csproj'. Cannot add package reference.
I have also tried using the Nuget manager and I get this when I try to build the project
/Users/jon/Desktop/hello-world/helloworld/helloworld/MTOUCH: Error MT0009: Error while loading assemblies: /Users/jon/.nuget/packages/ditto/1.1.8/runtimes/win/native/dittoffi.dll. (MT0009) (helloworld)
Any thought??

PrivateFontCollection not found Error in c# (linux)

I'm using command dotnet build in order to build a game in the MonoGame framework in Ubuntu 20.04 using .NET 5.0.
It was fine in Windows, but now that I'm using it here, it gives me this error:
error CS1069: The type name 'PrivateFontCollection' could not be found in the namespace 'System.Drawing.Text'. This type has been forwarded to assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' Consider adding a reference to that assembly. [/home/mrwoto/Ali/Programming/csharp/SAO/SAO/SAO.csproj]
So, is there anyway to resolve it? How can I add a reference to it in .csproj file?
One option is to add it from the terminal with
dotnet add package System.Drawing.Common
After this, you should be able to see something like the following in the .csproj file.
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
Please note that dotnet add is more than just adding some text to csproj.
From dotnet add package:
The dotnet add package command provides a convenient option to add a package reference to a project file. After running the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes, a <PackageReference> element is added to the project file and dotnet restore is run.

VS2019 extension using IDebugEventCallback2

I created a new VS extension using VS2019 16.1.6.
and I added this using statement
using Microsoft.VisualStudio.Debugger.Interop;
and added the interface IDebugEventCallback2 to my class
public sealed class VSIXProject1Package : AsyncPackage, IDebugEventCallback2
Not I get the error:
error CS0433: The type 'IDebugEventCallback2' exists in both 'Microsoft.VisualStudio.Debugger.Interop, Version=8.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'Microsoft.VisualStudio.Debugger.InteropA, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
How can I get rid of this error? Or is there an other way to react to debugger events than using IDebugEventCallback2?
edit:
Problem reported to Microsoft:
https://developercommunity.visualstudio.com/content/problem/651199/vs2019-extension-using-idebugeventcallback2.html
VS2019 uses PackageReference format to manage nuget packages for VSIX project.
And by default it will reference Microsoft.VisualStudio.SDK and Microsoft.VSSDK.BuildTools package.Also, since Microsoft.VisualStudio.SDK package have dependencies on many other packages, this project will also reference those packages.
See this simple structure:
Microsoft.VisualStudio.SDK
......(other dependencies)
--Microsoft.VisualStudio.Debugger.Interop
--Microsoft.VisualStudio.OLE.Interop
--Microsoft.VisualStudio.Debugger.Interop.10.0
--Microsoft.VisualStudio.Debugger.InteropA
......(11.0,12.0,14.0,15.0)
--Microsoft.VisualStudio.Debugger.Interop.16.0
--Microsoft.VisualStudio.Debugger.InteropA
So it's clear this issue results from the VSIX project adds reference to both Microsoft.VisualStudio.Debugger.Interop and Microsoft.VisualStudio.Debugger.InteropA.
These two assemblies have the same namespace Microsoft.VisualStudio.Debugger.Interop, and all have IDebugEventCallback2 Interface. I think it's why causes this issue.
As a workaround:
Normal we can use extern alias for this situation. But it hasn't supported for PackageReference format yet. Fortunately I found a good hint from gertjvr. So all we need is:
Unload the project=>Edit the xxx.csproj=>Add the content below into the project file:
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
<ItemGroup>
<ReferencePath Condition="'%(FileName)' == 'Microsoft.VisualStudio.Debugger.Interop'">
<Aliases>signed</Aliases>
</ReferencePath>
</ItemGroup>
</Target>
You can change the ReferencePath to Microsoft.VisualStudio.Debugger.InteropA if you want to use the Interface from this assembly. It depends on your need.

Error when referring .Net Standard project in Xamarin Android Project

I'm getting this error when I add a reference to the .Net Standard project in the Andoid Project.
Severity Code Description Project File Line Suppression State
Error Can not resolve reference: System.Threading.Tasks.Extensions,
referenced by DotNetty.Transport. Please add a NuGet package or
assembly reference for System.Threading.Tasks.Extensions, or remove
the reference to DotNetty.Transport. VFMApp.Droid
I tried:
Neither NuGet packages (System.Threading.Tasks.Extensions / DotNetty.Transport), clean solution, compiled project successfully, reference project, compile: ERROR
NuGet package for DotNetty.Transport, clean solution, compiled project successfully, reference project, compile: ERROR
NuGet package for System.Threading.Tasks.Extensions, clean solution, compile project successfully, reference project, compile: ERROR
Both NuGet packages (System.Threading.Tasks.Extensions / DotNetty.Transport), clean solution, compile project successfully, reference project, compile: ERROR
Packages in .Net Standard project:
Acr.UserDialogs 7.0.1
Humanizer 2.5.16
Microsoft.Azure.Devices.Client 1.18.1
Microsoft.Azure.Mobile.Client 4.1.1
Microsoft.Azure.Mobile.Client.SQLiteStore 4.1.1
NETStandard.Library 2.0.3
Plugin.Share 7.1.1
Refractored.MvvmHelpers 1.4.1-beta
Xam.Plugin.Connectivity 4.0.0.190-beta
Xam.Plugin.DeviceInfo 4.1.0-beta
Xam.Plugin.Geolocator 4.5.4-beta
Xam.Plugin.Media 4.1.1-beta
Xam.Plugins.Settings 4.0.0.10-beta
Packages in Android project:
Xamarin.Android.Support.Compat 28.0.0
Xamarin.Android.Support.Design 28.0.0
Xamarin.GooglePlayServices.Maps 60.1142.1
I was able to get the same error as you when I referenced DotNetty.Transport from a Xamarin.Android project compiling/targeting against API Level 28. It seems to be an issue with System.Threading.Tasks.Extensions v4.5.1 that DotNetty.Transport is referencing. Here is a link to a similar problem from another project:
https://github.com/dotnet/reactive/issues/803
To sum up the issue, it looks like that Systems.Threading.Tasks.Extensions v4.5.1 has an empty profile for MonoAndroid10. Because the profile is empty, it can not resolve the System.Threading.Tasks.Extensions.dll file, thus the error.
To fix this, you have to update your android *.csproj file and redirect the reference to use the System.Threading.Tasks.Extensions.dll that is defined in the netstandard2.0 profile.
I performed the following steps:
Add the System.Threading.Tasks.Extensions v4.5.1 nuget package to your Xamarin.Android project.
Add the System.Runtime.CompilerServices.Unsafe v4.5.2 nuget package to your Xamarin.Android project
Close Visual Studio.
Open your Xamarin.Android *.csproj file with a Text Editor.
Add another <ItemGroup> to tell your project to use the .netstandard2.0 profile instead of the MonoAndroid10 profile
<ItemGroup>
<Reference Include="System.Threading.Tasks.Extensions">
<HintPath>$(UserProfile)\.nuget\packages\system.threading.tasks.extensions\4.5.1\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
</Reference>
</ItemGroup>
So it should look something like this:
Save the file and reload your project in visual studio. After I did that I was able to compile successfully.

Categories