In a Xamarin.Forms app, I calling Humanizer from the Core (.Net Standard project)
I'm using the Nugets Humanizer.Core and Humanizer.Core.ru package for Russian
And calling it
DateTime.UtcNow.AddMinutes(-3).Humanize(culture: new CultureInfo("ru-Ru"));
And always I get english
like 3 minutes ago
I tried apply:
CultureInfo ci = new CultureInfo("ru-Ru");
Thread.CurrentThread.CurrentCulture = ci;
Thread.CurrentThread.CurrentUICulture = ci;
And these not infleunt on a result, I get again english.
I resolved the issue with the workaround.
I removed from Nuget all Humanize packages.
Follow to the packages directory: C:\Users\USERNAME\.nuget\packages
Need to copy files Humanize dll's from next's folders:
humanizer.core\2.8.26\lib\netstandard2.0 (Humanizer.dll, Humanizer.xml)
humanizer.core.ru\2.8.26\lib\netstandard2.0 (copy folder "ru" with file - ru\Humanizer.resources.dll)
Into my project folder I created CommonResources folder.
Then I created Humanize folder into CommonResources and pasted 2 files and "ru" folder to my Humanize.
Add references to PCL project yourProject.csproj file on these dll's.
<ItemGroup>
.......
<Reference Include="Humanizer.Core">
<HintPath>..\..\CommonResources\Humanizer\Humanizer.dll</HintPath>
</Reference>
<Reference Include="Humanizer.Core.ru">
<HintPath>..\..\CommonResources\Humanizer\ru\Humanizer.resources.dll</HintPath>
</Reference>
.......
<PackageReference Include="Xamarin.Forms" Version="5.0.0.2012" />
</ItemGroup>
After the dll files were added I got localized text into my project.
Thx #polyariz, I can confirm this still works with .NET MAUI, just copy the .dlls to the Resources folder...
and add them to the project via right-click on Dependencies and "Add Project Reference..."
Related
I have a project which is referring packages from nuget. These packages from nuget have their XML documentation file included as part of the package (present in .nupkg file at /lib/netstandard2.0/<projectName>.xml along with <projectName>.dll file)
The XML documentation file is getting generated by adding below in csproj file:
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Now when I am publishing the project which has these nuget packages references, the xml documenation file of the referred nuget packages is not becoming part of publish.
It seems this is an ongoing issue.
Is there a workaround to include xml documentation of referred packages ?
Found a solution which is making this work. Added below in the `.csproj' file:
<Target Name="_ResolvePublishNuGetPackagePdbsAndXml"
AfterTargets="RunResolvePublishAssemblies">
<ItemGroup>
<ResolvedFileToPublish
Include="#(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).pdb')"
RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))"
DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))"
Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''
and Exists('%(RootDir)%(Directory)%(Filename).pdb')" />
<ResolvedFileToPublish
Include="#(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).xml')"
RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))"
DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))"
Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''
and Exists('%(RootDir)%(Directory)%(Filename).xml')" />
</ItemGroup>
</Target>
It will make xml (and pdb if present) files of referred packages become part of published files.
Is Nuget package copy feasible in .Net Core?
I'm worried since, there is neither project.json nor package.config. Does it mean manually editing .csproj is the only way to go forward.
There has to be more efficient way, IMHO. Am I missing something.
I use a shared Directory.Build.props file to build same packages across multiple projects for .NET Core 2.0. So if you put this file in a shared folder for all your projects and simply import it after you create a new project, it does save a lot of time.
First create a shared Directory.Build.props file. Below I am adding NLog package for all my projects. Sample content for file:
<Project>
<ItemGroup>
<PackageReference Include="NLog" Version="4.5.6" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.5.4" />
</ItemGroup>
</Project>
Now import this file to root of your projects by right clicking the project 1 > Add > Existing Item > Directory.Build.props. Repeat the same for your other projects; project 2, project 3, etc. Notice that when you add the file each to your projects; NLog packages from Directory.Build.props file is automatically added as Nuget package.
Simply edit the XML and more package references under <ItemGroup></ItemGroup> for your packages. I hope this will be more efficient solution for you. It certainly saves me lot of time for new .NET Core projects. You can read more about customising build here.
If a library (eg, on github) doesn't distribute itself via a nuget package, I'd have to manually include it as a reference, correct? I see a lot of reference posts for how to add a reference to a project for Visual Studio, but I can't seem to figure out how to do it on Visual Studio Code.
In this case, I've downloaded the library's zip, and moved the expanded folder into my project, and then tried using <namespace>, which did not work.
EDIT:
I noticed that this downloaded zip contained a .nuspec. Is there something I can do with this file extension to import it in my project?
Let's say you have two projects:
1) Project1.Api
2) Project2.Executable
Command line syntax for dotnet add reference:
cd Project2.Executable
dotnet add reference ../Project1.Api/Project1.Api.csproj
If you check the Project2.Executable.csproj file, you will see the following entry:
<ItemGroup>
<ProjectReference Include = "..\Project1.Api\Project1.Api.csproj" />
</ItemGroup>
Add "vscode-solution-explorer" Extension. It will folder structure as visual studio.
Right click on project --> Add Reference --> Select the reference project from the list.
You can open .csproj file of the project you want to add reference to and add project reference like this:
<ItemGroup>
<ProjectReference Include = "<RELATIVE_PATH_TO_REFERENCE_PROJECT>" />
</ItemGroup>
If the ItemGroup for ProjectReference already exist then you can just add to it.
Example:
<ItemGroup>
<ProjectReference Include = "../MyLibrary.csproj" />
</ItemGroup>
In visual studio, in the solution explorer, expand the project that will reference this other library. You will see "References", right click and choose "Add". Then choose browse on the left. Find your dll in your file system. If vs can't find the library you may need to unzip it. I've read where you may need to copy the dll into the bin folders, I recommend trying it without doing that, then copying it in to them if it fails without them.
Btw Googling "visual studio add reference" comes up with A LOT of great results.
Using VS 2017 15.4.0
Following James Montemagno "Upgrading to Xamarin.Forms to .NET Standard"
https://channel9.msdn.com/Shows/XamarinShow/Snack-Pack-15-Upgrading-to-XamarinForms-to-NET-Standard?ocid=player
When trying to Clean/Build I am receiving the error:
Severity Code Description Project File Line Suppression State
Error Duplicate 'EmbeddedResource' items were included. The .NET SDK includes 'EmbeddedResource' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultEmbeddedResourceItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'App.xaml'; 'MainPage.xaml' App5.core C:\Program Files\dotnet\sdk\2.0.2\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.DefaultItems.targets 274
Any solution please?
Found the solution...
Right click on the new .NET Standard project I have created "App5" and choose Edit App5.csproj
I have deleted this code from the file and the error gone.
<ItemGroup>
<EmbeddedResource Include="App.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="MainPage.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
I found various suggestions, but this answer was easily the best for me, both in simplicity and elegance:
In Solution Explorer, enable "Show All Files". This displays all files in each folder, including those excluded from the project.
For each item listed in the error message:
Exclude from project
Include in project
Then
In Solution Explorer, disable "Show All Files".
My mistake was that I added embedded resource while simulator with app was running.
Soo... I had THIS added automatically inside .csproj file:
<EmbeddedResource Include="**/*" />
Remove it, and then everything should be fine
According to bugzilla of xamarin at some point you were required to insert to make it work with the new csproj format.
<ItemGroup>
<!-- https://bugzilla.xamarin.com/show_bug.cgi?id=55591 -->
<None Remove="**\*.xaml" />
<Compile Update="**\*.xaml.cs" DependentUpon="%(Filename)" />
<EmbeddedResource Include="**\*.xaml" SubType="Designer" Generator="MSBuild:UpdateDesignTimeXaml" />
</ItemGroup>
Source
I would imagine that xamarin decided to add that to the default build targets now.
So to fix it you have to do the following:
Open your shared .csproj file.
Remove all Itemgroups related to adding xaml pages and *.cs
clean + rebuild.
It happened to me in MS Visual Studio for Mac after I have added two font files as embedded resources.
These files were titled with the same prefix (Lora-Regular.ttf & Lora-Bold.ttf) and it looks like my IDE did handle this in a bad way.
Indeed, the following weird line was inserted in my .csproj file :
<EmbeddedResource Include="**/*" />
All I did was removing this line and error disapeared.
Try to clean it manually with these steps:
Close your VS
remove bin and obj folders from iOS, Android and the Common (Your project name) folder.
remove all content from the packages folder
open a terminal, navigate to your projects folder and type nuget locals all -clear
then type nuget restore
and finally open VS again and let me know if the problem still exists
For me issue was in one file name. I used underscore (_) in the filename. I was working with file name AppResource.zh_cn.resx. May be it could help someone.
for me unloading and reloading project again worked!
I have a web application project that references a third party assembly, which in turn uses some native dlls that it needs to find at runtime.
Because of that, I wanted to add these dlls to the bin folder of the project, so that they can definitely be found.
However, if I add the files to the project in /bin/, select "copy to output", the files are compiled and published into /bin/bin. Adding them to the root folder works, but can hardly be the right solution.
Adding them to the build target "AfterBuild" has no effect when publishing (e.g. "build deployment package")
It also has to work when building the solution via TFS, where the MSBuild target _CopyWebApplicationLegacy is invoked.
The solution was a combination of the things I had tried already:
Include the "Bin" folder in the project
Add the needed files (I added them as a link due to our development structure)
Set the following properties: "Build Action = Content" and "Copy to Output = Do Not Copy"
The files are now copied to the bin folder when publishing, even when automating the builds on TFS.
The component that needed this was GdPicture, which uses a couple of native DLLs during runtime.
It's common to have a lib folder in either your solution or workspace to put your third party dlls within. You would then add a reference to this location from your project and ensure this location is under source control.
You could also look at using NuGet to package this for you, which uses a solution level packages folder automatically.
Based on this article http://sedodream.com/2010/05/01/WebDeploymentToolMSDeployBuildPackageIncludingExtraFilesOrExcludingSpecificFiles.aspx. It's possible to define the msbuild target into main (lastest in order of solution's build) project file that will capture all files of the bin folder. Like this
<Target Name="CustomCollectFiles">
<ItemGroup>
<_CustomFiles Include="$(OutDir)\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>$(OutDir)\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
And place it before closing root project element.