Xamarin.Forms SDK-Style multiplatform project with XAML - xamarin.forms

Have defined multitarget project:
<Project Sdk="MSBuild.Sdk.Extras/2.0.54">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;xamarinios10;monoandroid9.0;</TargetFrameworks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Xamarin.Forms" Version="4.6.0.800" />
<PackageReference Include="Xamarin.Essentials" Version="1.5.3" />
<Compile Include="**\Shared\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('xamarinios')) ">
<Compile Include="**\iOS\*.cs" />
</ItemGroup>
<ItemGroup Condition=" $(TargetFramework.StartsWith('monoandroid')) ">
<Compile Include="**\Android\*.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Shared\MyView.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
So, when i make my custom component only in code all compile and works well, but i would like to develop some custom controls using XAML.
But i got error of ambiguous call to method InitializeComponent() in MyView object.
How to make correct conditional configuration in .csproj for compiler to understand *.xaml and *.xaml.cs files ?

Adding these properties to common ItemGroup solved the problem:
<None Remove="**\Shared\*.xaml" />
<Compile Include="**\Shared\*.xaml.cs" DependentUpon="%(Filename)" />
<EmbeddedResource Include="**\Shared\*.xaml" Generator="MSBuild:UpdateDesignTimeXaml" />

Related

How to make Nop-Commerce 4.20 plugin ready for distribution

I am working with the new plugin of Nopcommerce 4.20. The plugin is almost completed but I need to make the plugin ready for distribution. But there are unnecessary folders created inside Nop.Web/Plugins/.
I made the Nop.Web and Nop.Web.Framework to "copy local=false" which are under Projects and deleted the plugin and build it again. But still, I am getting the unnecessary folders with two characters.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Copyright>SOME_COPYRIGHT</Copyright>
<Company>YOUR_COMPANY</Company>
<Authors>SOME_AUTHORS</Authors>
<PackageLicenseUrl>PACKAGE_LICENSE_URL</PackageLicenseUrl>
<PackageProjectUrl>PACKAGE_PROJECT_URL</PackageProjectUrl>
<RepositoryUrl>REPOSITORY_URL</RepositoryUrl>
<RepositoryType>Git</RepositoryType>
<OutputPath>..\..\Presentation\Nop.Web\Plugins\Discount.ProductMix
</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<!--Set this parameter to true to get the dlls copied from the NuGet
cache to the output of your project. You need to set this parameter to
true if your plugin has a nuget package to ensure that the dlls copied
from the NuGet cache to the output of your project-->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<None Remove="logo.jpeg" />
<None Remove="plugin.json" />
<None Remove="Views\Configure.cshtml" />
<None Remove="Views\DiscountProductAddPopup.cshtml" />
<None Remove="Views\_ViewImports.cshtml" />
</ItemGroup>
<ItemGroup>
<Content Include="logo.jpeg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Views\DiscountProductAddPopup.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\Configure.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj">
<Private>false</Private>
</ProjectReference>
<ProjectReference Include="..\..\Presentation\Nop.Web\Nop.Web.csproj">
<Private>false</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Update="Controllers\DiscountProductMixController.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Update="Data\DiscountOfferMixMap.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Update="Data\DiscountProductMixObjectContext.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Update="DiscountProductMixConfiguration.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Update="Domain\DiscountOffers.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Update="Infrastructure\DependencyRegistrar.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Update="Infrastructure\PluginDBStartup.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
<Compile Update="Models\ConfigurationModel.cs">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Compile>
</ItemGroup>
<!-- This target execute after "Build" target -->
<Target Name="NopTarget" AfterTargets="Build">
<!-- Delete unnecessary libraries from plugins path -->
<MSBuild Projects="#(ClearPluginAssemblies)" Properties="PluginPath=$(MSBuildProjectDirectory)\$(OutDir)" Targets="NopClear" />
</Target>
All things are perfect if you are not installing any Nuget Packages then please make false
<CopyLocalLockFileAssemblies>False</CopyLocalLockFileAssemblies>
and another thing
Add replace these lines
<ItemGroup>
<ProjectReference
Include="..\..\Presentation\Nop.Web.Framework\Nop.Web.Framework.csproj"/>
<ProjectReference Include="..\..\Presentation\Nop.Web\Nop.Web.csproj" />
<ClearPluginAssemblies Include="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" />
Try these changes can help you.
I also had a problem with unnecessary folders being created. This turned out to be caused by the .Net Core 3.0 SDK, which apparently builds plugins in a different way than the version 2.x SDK's did. To check for this, you can run dotnet --version from the command line from within your nopcommerce project folder. The version should not be higher than 2.x.
The fix was to just tell dotnet to use a specific SDK version for building the project. This was just a matter of adding a global.json file in my nopcommerce project folder containing these lines:
{
"sdk": {
"version": "2.2.402"
}
}
Running dotnet --version again now gives the output 2.2.402.

WASM WebAssembly FileNotFoundException from System.Private.CoreLib

I am trying to use https://platform.uno/ to build some tools. The WASM (WebAssembly)-Project from uno-platform template will not start due to FileNotFoundExceptions regarding some base Microsoft libs.
I created a new uno-platform APP from uno template. I have updated all NuGet packages to latest version. When I start the wasm web-project I get the following exceptions (at bootstrap i guess):
followed by:
followed by:
Here you can see the Exception class comes from the namespace that was not found in picture 1. It's very strange to me and I don't know whats up anymore.
I guess this is an issue with prerequisites or wrong versions in dependencies somewhere. Does anybody know whats up?
Here is the csproj of the WASM project:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netstandard2.0</TargetFramework>
<WasmHead>true</WasmHead>
<DefineConstants>$(DefineConstants);__WASM__</DefineConstants>
<NoWarn>NU1701</NoWarn>
<StartupObject>Macs3.Calculations.TestTool.Wasm.Program</StartupObject>
<MonoRuntimeDebuggerEnabled>true</MonoRuntimeDebuggerEnabled>
</PropertyGroup>
<ItemGroup>
<Content Include="..\Macs3.Calculations.TestTool.UWP\Assets\*.png" Link="Assets\%(FileName)%(Extension)" />
<Content Include="Fonts\winjs-symbols.woff2" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="WasmCSS\Fonts.css" />
<EmbeddedResource Include="WasmScripts\AppManifest.js" />
</ItemGroup>
<ItemGroup>
<LinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>
<ItemGroup>
<!--
This item group is required by the project templace because of the
new SDK-Style project, otherwise some files are not aded automatically.
You can safely remove this ItemGroup completely.
-->
<Compile Remove="Program.cs" />
<Compile Include="Program.cs" />
<Content Include="LinkerConfig.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Uno.UI" Version="1.46.0-dev.2039" />
<PackageReference Include="Uno.Wasm.Bootstrap" Version="1.0.0-dev.298" />
</ItemGroup>
<Import Project="..\Macs3.Calculations.TestTool.Shared\Macs3.Calculations.TestTool.Shared.projitems" Label="Shared" Condition="Exists('..\Macs3.Calculations.TestTool.Shared\Macs3.Calculations.TestTool.Shared.projitems')" />
</Project>

Nuget Packages Conflict .net core

I'm working on creating sample for clean architecture. When I had made core and infrastructure projects there were no problems. No I had add new API project and I got problem, picture bellow
I had tried to add project references in csproj but still have a problem, can anyone help me to fix this problem ?
Here is the link for project: https://github.com/danijel88/Clean-Architecture
Regards,
Danijel
Here's a question similar to yours
Here's a sample .csproj. Be sure to have
<TargetFramework>netcoreapp2.2</TargetFramework>
Make sure your project is on 2.2 before updating your packages to 2.2.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TypeScriptToolsVersion>3.1</TypeScriptToolsVersion>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
<CopyRefAssembliesToPublishDirectory>false</CopyRefAssembliesToPublishDirectory>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Gelf.Extensions.Logging" Version="1.5.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.1" />
<PackageReference Include="SlackLogger" Version="2.0.5" />
<PackageReference Include="System.Xml.Linq" Version="3.5.21022.801" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nozomi.Infra.Preprocessing\Nozomi.Infra.Preprocessing.csproj" />
<ProjectReference Include="..\Nozomi.Infra.Service.Identity\Nozomi.Infra.Service.Identity.csproj" />
<ProjectReference Include="..\Nozomi.Infra.Service\Nozomi.Infra.Service.csproj" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="Areas\Identity\Pages\_ViewImports.cshtml" />
</ItemGroup>
</Project>

Call awaited database context methods in F#

I have defined a context (inherited from DbContext) and in C# I use:
await _context.People.SingleOrDefaultAsync()
But having the context in the F# code, the *Async methods don't exist:
_context.People...
How can I call SingleOrDefaultAsync?
I am using Entity Framework Core.
This is my .fsproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="PeopleQuery.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.1.4" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Domain.People.csproj" />
</ItemGroup>
</Project>

dotnet compiler error while publishing f# project

I am trying to publish a dotnet core 2.0.0 (release version) project from command line.
I am getting an error as below.
EXEC(1,1): error CS8301: Invalid name for a preprocessing symbol; '' is not a valid identifier [C:\Work\FloAppGit\FloAppStpl\FloMa
nufacturer\FloManufacturer.fsproj]
C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.0\build\netstandard2.0\Microsof
t.AspNetCore.Mvc.Razor.ViewCompilation.targets(60,5): error MSB3073: The command ""C:\Program Files\dotnet\dotnet.exe" exec --runt
imeconfig "C:\Work\FloAppGit\FloAppStpl\FloManufacturer\bin\Debug\netcoreapp2.0\FloManufacturer.runtimeconfig.json" --depsfile "C:
\Work\FloAppGit\FloAppStpl\FloManufacturer\bin\Debug\netcoreapp2.0\FloManufacturer.deps.json" "C:\Program Files\dotnet\sdk\NuGetFa
llbackFolder\microsoft.aspnetcore.mvc.razor.viewcompilation\2.0.0\build\netstandard2.0\Microsoft.AspNetCore.Mvc.Razor.ViewCompilat
ion.dll" #"obj\Debug\netcoreapp2.0\microsoft.aspnetcore.mvc.razor.viewcompilation.rsp"" exited with code 1. [C:\Work\FloAppGit\Flo
AppStpl\FloManufacturer\FloManufacturer.fsproj]
My project file is as follows.
<Project Sdk="FSharp.NET.Sdk;Microsoft.NET.Sdk.Web">
<PropertyGroup>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.0</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Compile Include="Controllers/*.fs" />
<Compile Include="FloLogger.fs" />
<Compile Include="Restful.fs"/>
<Compile Include="AppSettingsHelper.fs" />
<Compile Include="DataRecords/BusinessRecords.fs"/>
<Compile Include="DAL/ManufacturerDAL.fs"/>
<Compile Include="DAL/ItemManufacturerDAL.fs"/>
<Compile Include="BAL/ItemManufacturerBAL.fs"/>
<Compile Include="BAL/ManufacturerBAL.fs"/>
<Compile Include="Manufacturer.fs" />
<Compile Include="ItemManufacturer.fs" />
<Compile Include="Startup.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
<PackageReference Include="log4net" Version="2.0.8" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="RavenDB.Client" Version="4.0.0-beta-40016" />
<PackageReference Include="Polly" Version="5.1.0" />
<PackageReference Include="Suave" Version="2.0.3.0" />
<PackageReference Include="Suave.AspNetCore" Version="0.3.0" />
<PackageReference Include="Suave.DotLiquid" Version="2.0.3" />
<PackageReference Include="xunit" Version="2.2.0" />
</ItemGroup>
Please help me resolve this issue as I am stuck.
I was able to resolve the issue by commenting these lines in the project file.
<PackageReference Include="FSharp.Core" Version="4.1.*" />
<PackageReference Include="FSharp.NET.Sdk" Version="1.0.*" PrivateAssets="All" />
Also I had to change the header of the project file like this.
<Project Sdk="Microsoft.NET.Sdk.Web">
Delete the obj and bin folders. Do a dotnet clean then dotnet restore.
I was able to publish the code successfully for dotnet core 2.0.0 release version.

Resources