Different Newtonsoft.Json.dll dotnet publish vs publish with Visual Studio - json.net

I have a .NET Core Web Application with target framework .netcoreapp2.0.
If i publish my application via Visual Studio (folder profile) I get a different Newtonsoft.Json.dll then with the command dotnet publish --configuration Release --output D:/publish/Frontend /property:PublishWithAspNetCoreTargetManifest=false
VS publish version:
dotnet publish version:
The created file AutomaticConfirmationWebfrontend.deps.json has always this dependency:
"runtime": {
"lib/netstandard1.3/Newtonsoft.Json.dll": {
"assemblyVersion": "10.0.0.0",
"fileVersion": "10.0.1.20720"
}
}
This results in a problem for my CI/CD process where I publish my app with the command dotnet publish. If I open the website I get an error message that the assembly Newtonsoft.JSON 10.0.0.0 could not be found. If i copy manually the DLL with version 10.0.0.0 to the application folder it works! Debugging my application locally works also fine!
I have no Newtonsoft NuGet package installed. I think I am using the built in package from .NET Core.
In my Startup.cs I have the following line of code:
services.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());
I need this for lowercase JSON objects. I have imported this namespace:
using Newtonsoft.Json.Serialization
Anybody an idea what I'm doing wrong or how to fix this?

I did 3 steps:
Upgraded to netcoreapp3.1
Removed all nuget packages from C:\Users\******\.nuget\packages
Installed the latest MSBuild installer

Late answer but it may help someone in future. Within the solution some other (other project) NuGet package also depending Newtonsoft.Json.dll. Check all your NuGet package dependencies especially Testing projects which may be mapped with low version Newtonsoft.Json.dll. (Refer below pic).
If that is the problem, then you can map .csproj file in your publish command like below,
dotnet publish src/myproject.csproj --configuration Release --output D:/publish/Frontend /property:PublishWithAspNetCoreTargetManifest=false

Related

Can I publish targeting linux-armv6 runtime in .NET Core 7?

According to this issue and this runtime list for .NET Core v7.0, linux-armv6 is supported. However, when I try to target it with dotnet publish -r linux-armv6 I get the following error:
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(135,5): error NETSDK1084: There is no application host available for the specified RuntimeIdentifier 'linux-armv6'.
What am I doing wrong?
armv6 in dotnet is only community supported. You can build it by yourself. If you want, I've build it from 7.0.0 source and put it in docker image for building my project. (I use linux-armv6/self contained)
https://hub.docker.com/r/taphome/dotnet7armv6
From my experience, dotnet is working pretty well on armv6. Problem is if you have some Nugets with native libraries which probably doesn't have armv6 version of native dependencies. I switched my app.libraries from mono/netstandard20 to net7 on armv6.

Nothing to do. None of the projects specified contain packages to restore dotnet restore

I am working on an ASP.NET Web API 2 project with .NET target framework 4.6.1. I am trying to setup github workflow for my repo. When the dotnet restore command is run, it throws an error like below.
I am getting the same error if I run the same command in from command prompt inside my project. Also if I run dotnet build, it shows below error.
The project builds fine from Visual Studio but not working from command line or github workflow yml. Can anyone please point me on what am I missing?
The project builds fine from Visual Studio but not working from command line
Check which sln file Visual Studio is using to build your project.
Since I don't see any sln/csproj in your GitHub repository, it is also possible that you have a .gitignore which would prevent adding those in the first place.
DOTNET Restore does not support pacakges.config https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore
So you have to move the nuget package references to csproj file itself
Here is a great comment on how to do that https://stackoverflow.com/a/65701746/8318698
Note: check that if multiple projectGuid is there on csproj at the end of the steps
After that you will be able to use dotnet restore without a hitch.

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

'{{FSharpCoreShippedPackageVersion}}' is not a valid version string

I just upgraded to Visual Studio 2019 version 16.5.0 Preview 2.0. It seems to have broken building and running .NET Core projects in F# with the dotnet command line tool.
Previously dotnet build and dotnet run worked fine. Now either one produces this error message (wrapped for readability):
C:\Program Files\dotnet\sdk\3.1.200-preview-014883\NuGet.targets(124,5):
error : '{{FSharpCoreShippedPackageVersion}}' is not a valid version string.
My projects don't have the string FSharpCoreShippedPackageVersion anywhere in them that I can see (including in the .fsproj files). I also looked in the referenced NuGet.targets file and couldn't find FSharpCoreShippedPackageVersion in it either.
Using dotnet new console --language=F# also fails, telling me to restore NuGet packages, but attempting dotnet restore gives the same error message.
What can I do to fix this?
UPDATE: This issue appears to be fixed in the current version of the preview:
3.1.200-preview-014977
If you update Visual Studio 2019 Preview, you shouldn't need this workaround anymore.
I found a workaround:
Run dotnet new globaljson in the project root folder
Edit the global.json to use .NET Core 3.1.101 instead of 3.1.200-preview-014883.
It appears that the combination of VS 2019 Version 16.5.0 Preview 2.0 and .NET Core 3.1.200-preview-014883 causes this problem.

New dotnet core project cannot restore

I attempted to create a new project using the yeoman generator, however when i then move into the folder to restore the dependencies I encounter an error.
I start in an empty directory then execute the following
yo aspnetcore-spa (select the Aurelia framework and .csproj project type)
dotnet restore
I get the following error
warn : The folder '<path>/projFolder' does not contain a project to restore.
.NET Core projects using csproj require at least .NET Core CLI Preview 3. Double check which version is being used by running dotnet --info. If it is 1.0.0-preview2 or 1.0.0-preview2-1, it does not support csproj.
At the time of writing, the SDKs that support csproj are not listed on the main .NET Core download page. The latest is the RC3 release of .NET Core CLI.
https://github.com/dotnet/core/blob/master/release-notes/rc3-download.md
If you have installed the new SDK and dotnet --info still shows an older version, check for a global.json file in the current directory or any parent directories and make sure the "sdk" setting has the right version. The aspnetcore-spa generated creates a global.json file with SDK 1.0.0-preview3-004056, which is not the latest SDK.
Just update your dotnet-core-framework-version.
I fixed this by doing:
apt-get remove dotnet-dev-1.0.0-preview2-1-003177
apt-get install dotnet-dev-1.0.0-rc4-004771
Then:
dotnet restore
worked.
Then, you must reinstall the framework 1.1.1:
apt-get install dotnet-sharedframework-microsoft.netcore.app-1.1.1
(currently [22.03.2017], Visual Studio 2017 will use .NET Core 1.1.1 when it does publish)
Also, when you run a published project, it's
dotnet yourdll.dll
and not
dotnet run yourdll.dll
Edit:
Just one day later, and you might want to
apt-get install dotnet-dev-1.0.1
instead of rc4. You can then skip sharedframework, as sharedframework 1.1.1 gets installed automatically with dotnet-dev-1.0.1.

Resources