Upgrading Entity Framework 4.3.1 to 5.0.0 beta 1 gives binding redirects error - entity-framework

My solution uses Entity Framework 4.3.1. I want to upgrade to 5.0.0 beta-1. The package manager gives the following output:
PM> Install-Package -IncludePrerelease EntityFramework
You are downloading EntityFramework from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=242870. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'EntityFramework 5.0.0-beta1'.
Successfully removed 'EntityFramework 4.3.1' from PROJECTNAME.
Successfully added 'EntityFramework 5.0.0-beta1' to PROJECTNAME.
Failed to generate binding redirects for 'PROJECTNAME'. 'object' does not contain a definition for 'References'
Successfully uninstalled 'EntityFramework 4.3.1'.
It looks like the upgrade completed succesfully, but I wonder how I could have prevented this error.

You should enable automatic binding redirection manually. To do this:
In Visual Studio, in Solution Explorer, right-click the project and choose "Unload Project".
Add the following element to the property group (under the tag) in XML code:
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
The following shows an example project file with the element inserted:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{123334}</ProjectGuid>
...
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
...
</Project>
Right click the project and choose "Reload Project".
Compile your app.
List item
Install EntityFramework.

Related

Errors with dotnet publish

I've used these resources to learn how to publish a MAUI app:
https://learn.microsoft.com/en-us/dotnet/maui/ios/deployment/overview
https://github.com/dotnet/maui/issues/4397
https://github.com/dotnet/sdk/issues/21877
Based on these, I tried different variants to publish, but none of them work:
dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64
error : The RuntimeIdentifier 'ios-arm64' is invalid.
dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 --no-restore
error NETSDK1032: The RuntimeIdentifier platform 'ios-arm64' and the
PlatformTarget 'x64' must be compatible.
dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true
error : The RuntimeIdentifier 'ios-arm64' is invalid.
dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true --no-restore
error NETSDK1032: The RuntimeIdentifier platform 'ios-arm64' and the
PlatformTarget 'x64' must be compatible.
Update
Environment:
Windows 10 Home - 21H2
VS 2022 Version 17.3.0 Preview 1.1
Update 2
Based on the answers I have now this csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-ios</TargetFrameworks>
<OutputType>Exe</OutputType>
<RootNamespace>MonkeyFinder</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Display name -->
<ApplicationTitle>MonkeyFinder</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.testapp.monkeyfinder</ApplicationId>
<ApplicationIdGuid>E46570A0-D087-4FC2-ADFE-58FEAB0BEBB9</ApplicationIdGuid>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<!-- Required for C# Hot Reload -->
<UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<CodesignKey>‌xxx</CodesignKey>
<CodesignProvision>Development Test Provisioning</CodesignProvision>
<ArchiveOnBuild>true</ArchiveOnBuild>
<TcpPort>58181</TcpPort>
<ServerAddress>xxx</ServerAddress>
<ServerUser>xxx</ServerUser>
<ServerPassword>xxx</ServerPassword>
<_DotNetRootRemoteDirectory>/Users/xxx/Library/Caches/Xamarin/XMA/SDKs/dotnet/</_DotNetRootRemoteDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-android|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-maccatalyst|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-maccatalyst|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-windows10.0.19041|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-windows10.0.19041|AnyCPU'">
<MtouchDebug>True</MtouchDebug>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
And then I tried out these commands based on more collected information since, with the following results:
dotnet publish -f:net6.0-ios -c:Release
A runtime identifier for a device architecture must be specified in order to publish this project. 'iossimulator-x64' is a
simulator architecture.
dotnet build -c:Release /p:BuildIpa=true
Successful, but there is no *.ipa file in bin/Release/net6.0-ios/ios-arm64/publish
I also removed the other PropertyGroup tags, but it made no difference. Expect when removing the first one, then the error is:
error NETSDK1013: The TargetFramework value '' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.
And also the project doesn't load properly anymore.
Update 3:
When I create a brand new .NET MAUI project from the template it starts compiling with the command
dotnet publish -f:net6.0-ios -c:Release
But even when I copy the xml in the csproj file from the working to the not working project I get the error:
A runtime identifier for a device architecture must be specified in
order to publish this project. 'iossimulator-x64' is a simulator
I guess this indicates that the cause for the error is actually not to be found in the csproj file, but somewhere else?
My solution is to run it on a Mac. Don't run it on your Window machine.
At the moment, you may want to install Visual Studio 2022 Preview for Mac and Open Terminal of your project. Then, run the command with sudo.
Example:
sudo dotnet publish -f:net6.0-ios -c:Release
Note: I set all of my properties in PropertyGroup in the Maui Project
Worked like a champ!
FIX 1
Try including RuntimeIdentifier via a conditional property group in .csproj, and omit it from command line.
From Add code signing ....
.csproj:
<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<CodesignKey>iPhone Distribution: John Smith (AY2GDE9QM7)</CodesignKey>
<CodesignProvision>MyMauiApp</CodesignProvision>
<ArchiveOnBuild>true</ArchiveOnBuild>
</PropertyGroup>
Command line:
dotnet publish -f:net6.0-ios -c:Release
FIX 2
For now, when publish for ios, remove other target frameworks from .csproj. NOTE: This shouldn't be needed, because you specify framework via -f, but its worth a try.
Change:
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
To:
<TargetFrameworks>net6.0-ios</TargetFrameworks>

ERROR: NU1605 "Detected package downgrade" - how to enforce downgrade in .Net5

In the past (and according to current documentation) referencing downgraded nuget package eliminated the above NU1605 (warn/err).
Now, with dotnet SDK 5.0.302, it seems impossible. A sample solution demonstrating it:
MyLib reference 1 nuget package : Newtonsoft.Json 13.0.1
My empty solution has this csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="MyLyb" Version="1.0.0" />
</ItemGroup>
</Project>
Still, I get
error NU1605: Detected package downgrade: Newtonsoft.Json from 13.0.1 to 12.0.3. Reference the package directly from the project to select a different version.
(building from cli, no visual studio involved)
I also tried "excludeAssets" with no help.
How can I reference lower version and avoid this error (without hiding it using "NoWarn")

Migrating a build to VSTS - get warning messages and no artifacts in the drop folder

I have a legacy application where I want to migrate the build to VSTS.
In the application is a web project and a WCF API that I want to include in the build, and a WIN RT client project that should not be included.
So I instead of having a single Visual Studio task to build the sln file, I have 2 which build the web and WCF projects individually one after the other.
See
Although the build is successful, I get these warnings and I would like to know how to fix them;
The log files can be found here; https://1drv.ms/f/s!ArKf9AZKW_zWgRapkZ_IUT-DrhY0
The property groups in my csproj file are;
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
If I replace the build for 2 project csproj files with one with the overall sln file, I get these error messages;
C:\Program Files
(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2049):C:\Program
Files
(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2049,5):
Error MSB3779: The processor architecture of the project being built
"Any CPU" is not supported by the referenced SDK "Bing.Maps.Xaml,
Version=1.313.0825.0". Please consider changing the targeted processor
architecture of your project (in Visual Studio this can be done
through the Configuration Manager) to one of the architectures
supported by the SDK: "x86, x64, ARM". C:\Program Files
(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2049):C:\Program
Files
(x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2049,5):
Error MSB3779: The processor architecture of the project being built
"Any CPU" is not supported by the referenced SDK "Microsoft.VCLibs,
Version=12.0". Please consider changing the targeted processor
architecture of your project (in Visual Studio this can be done
through the Configuration Manager) to one of the architectures
supported by the SDK: "x86, x64, ARM". C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(2606):C:\Program
Files
(x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(2606,5):
Error : Copying file Service
References\SurveyServiceReference\M.Survey.SurveyAdminApp.SurveyServiceReference.AssignedJobs.datasource
to obj\Release\Package\PackageTmp\Service
References\SurveyServiceReference\M.Survey.SurveyAdminApp.SurveyServiceReference.AssignedJobs.datasource
failed. Could not find file 'Service
References\SurveyServiceReference\M.Survey.SurveyAdminApp.SurveyServiceReference.AssignedJobs.datasource'.
Process 'msbuild.exe' exited with code '1'.
Make sure you add the parameters to the MsBuild Arguments and that these are a valid combination for your project, e.g.:
/p:Configuration=Release /p:Platform=AnyCPU
Or edit the project file and make sure the default Configuration and Platform are specified in the first PropertyGroup:
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
</PropertyGroup>
It turned out it caused by the variable BuildPlatform = any cpu in your build definition.
You should change the variable BuildPlatform with the value anycpu (no blank space) to align with the value in PropertyGroups of your .csproj.
The Visual studio build task does have this weird behavior. When building a solution or .sln file, you have to provide the build platform in the following manner: With a space in between
However, when you are building a project or a .csproj file, you have to provide the build platform in the following manner: Without any space in between
If building the project individually doesn't work for you, and you need to build the solution, then this SO post will help you make solution level changes in Visual Studio so when you build in VSTS, the task will only build the desired projects. Hope this helps.

How to run PostShard samples from 2.1 to 4.1?

After download samples from Download - Samples – PostSharp
a "PostSharp Required" dialog was shown asking to install PostSharp 2.1.
I have PostSharp 4.1 installed in my machine, is there a way to run those samples using PostSharp 4.1?
Most samples should be compatible, but are not currently officially supported.
To convert them to the new PostSharp version, you need to edit the csproj file remove the following XML:
<!-- The next section automatically prompts you to install PostSharp if needed. It is not required in normal projects. -->
<UsingTask AssemblyFile="lib\PostSharp.MSBuild.Samples.exe" TaskName="PostSharp.MSBuild.Samples.LaunchPostSharpInstaller" />
<Target Name="PostSharp21Check" Condition="'$(PostSharp21Imported)'==''" >
<LaunchPostSharpInstaller ProjectPath="$(MSBuildProjectFullPath)" Version="2.1" ProjectGuid="$(ProjectGuid)" BuildingProject="$(BuildingProject)" />
<Error Text="To build this project, you must install PostSharp 2.1 on your machine or add it as a NuGet package to this project." />
</Target>
<PropertyGroup >
<ResolveReferencesDependsOn>PostSharp21Check;$(ResolveReferencesDependsOn)</ResolveReferencesDependsOn>
</PropertyGroup>
Additionally, you need to remove all referenced PostSharp assemblies - most likely only PostSharp.dll (either when editing the csproj file or after reopening).
After reopening the project, you should add PostSharp NuGet package, which will install the current version of PostSharp.

Packing NuGet projects compiled in release mode?

Is there some way to make a NuGet package using code compiled in release mode? Or is there some reason I should only publish (make available locally, in this case) packages compiled in debug mode?
Every time I call nuget pack from my project directory, where I have the nuspec file below, on code I have only compiled in release mode, it complains about not finding the DLL in the debug folder ("\bin\Debug\SomeProject.dll"). If I compile it in debug mode, those files are there and it packs them up as it should.
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>$id$</id>
<version>$version$</version>
<authors>$author$</authors>
<owners>$author$</owners>
<iconUrl>http://somewhere/project.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
</metadata>
</package>
You can solve it like this:
NuGet.exe pack Foo.csproj -Prop Configuration=Release
(reference)
If you are using a post-build event and you want to create a package whether using Debug or Release configuration you can setup the post-build event commandline like so:
"<path to nuget tools>\NuGet.exe" pack "$(ProjectPath)" -Prop Configuration=$(ConfigurationName)
To have NuGet automatically use Release mode when you run nuget pack, do the following:
Open your .csproj file in a text editor.
Find the following line:
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
In this line, replace Debug with Release.
Save changes.
The answers here are good, but I was having a lot of problems with this for a .NET Standard project. I had a project that was only going to publish Release binaries, but it wasn't respecting my default build output path.
I added this to my CSProj which then enabled me to use the accepted answer here.
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<OutputPath>$(SolutionDir)bin\$(PlatformTarget)\Release</OutputPath>
</PropertyGroup>
Chiming in here.
My build profile would build the DLLs to bin\<arch>\Debug|Release.
I was able to point to my folders by running the nuget command as follows:
Notice how I used the -p option.
PS > nuget pack -p Configuration="x64\Release"
Attempting to build package from ...
...
Found packages.config. Using packages listed as dependencies
...
- Add a dependency group for .NETFramework4.7.2 to the nuspec
Successfully created package...