Visual Studio for mac project.json - asp.net-core

When I use Visual Studio for Mac to create a web project with .Net core 1.1, there is no project.json in my project. Is there any mistake when I create
this project?

Project.json was never released in production. It was replaced by a new, vastly simplified MSBuild project format before .NET Core was released. The new format works a lot like the project.json format - it supports globbing, package references and compiles all *.cs* files found in a folder. You don't need to define dependent packages in the project file any more, you can specify *one* root package and all dependencies will be added when you executedotnet restore`
.NET Core allows you to add commandlets that appear as commands to the .NET CLI. dotnet watch executes the dotnet-watch executable. dotnet ef searches for and executes the dotnet-ef executable.
You have to add an option to the MSBuild project that installs the tool in the first place with the <DotNetCliToolReference> element. After that, dotnet restore will install the tool just like any other package.
This is described in .NET Core Command Line Tools for EF Core.
The MSBuild project file should look like this :
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
</Project>
This file is enough to build your project and execute ef commands from the command line, since all *.cs files will be compiled by default

project.json is deprecated and was never supported outside preview .NET Core tooling in VS 2015. The new tooling uses csproj files and can be used in VS 2017 and VS for Mac (and others like VSCode, Rider, …).

Related

WiX installer: problems with C# project in Sdk format "The default XML namespace of the project must be the MSBuild XML namespace."

I have a solution with several projects targeting .NET Framework 4.7.2 and including WiX installer.
Everything works and builds fine.
In order to convert projects to .net standard/.net 6 I first convert one of the projects (extremely simple class library) to a modern Sdk format. At this moment the project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="LegalNotice.rtf" />
</ItemGroup>
The library and all dependent projects build ok, but when building WiX installer it gives me the following error:
heat.exe(0,0): error HEAT5305: Failed to load project ...\MyProject.csproj: The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.
Ok, I add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the project. All projects build ok, except WiX installer which nog gives this error:
heat.exe(0,0): error HEAT5307: Build failed.
Just to try I add ToolsVersion="15.0", the project file now looks like this:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<RootNamespace>MyProject</RootNamespace>
<AssemblyName>MyProject</AssemblyName>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="LegalNotice.rtf" />
</ItemGroup>
No luck. Like before, everything builds ok, except of WiX installer, which fails with the same 5307 error.
WiX version installed: 3.11.2 (the latest stable).
Any suggestions what could be the problem?
WiX v3.11 doesn't support SDK-style projects. WiX v4 will support SDK-style projects. Supporting SDK-style projects is actually, one of the biggest if not the biggest feature in WiX v4.

Cannot find `SignalR` in `Microsoft.AspNetCore.App` in .NET Core 2.2?

I'm not so sure why this can be a problem, I've just revised some documentation about SignalR in ASP.NET Core and it seems to mean that I don't have to install any additional package (already have Microsoft.AspNetCore.All and Microsoft.AspNetCore.App referenced after creating a new ASP.NET Core project (version 2.2).
I've even tried Googling and found this blog post: https://wakeupandcode.com/real-time-asp-net-core-web-apps-with-signalr/#dep
It was written on Dec 23 2018, and the author does confirm that we don't need to install any additional package.
Well so it's really playing on me, making me have a feeling of being stupid, not so sure why I cannot use SignalR in my project (I'm not intending to install any additional package, which I think should work for me), just wonder why it's not already available. The following code does not compile:
using Microsoft.AspNetCore.SignalR;
It reports that SignalR does not exist in the namespace Microsoft.AspNetCore right in the project that has Microsoft.AspNetCore.All and Microsoft.AspNetCore.App.
Actually I cannot find the Microsoft.AspNetCore.SignalR when expanding the references tree.
The documentation says nothing about where to import the module (which means it should already be available). As I said the project targets .NET Core 2.2. Could you explain to me something could be wrong here?
PS: My project is a Web API (not MVC) project.
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Autofac" Version="4.9.4" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.2.0" />
</ItemGroup>
Usually, project templates have outdated libraries. Use the NuGet package manager to update references to recent versions and try again. It should help.

What is the default version of the nuget package when referenced with PackageReference in .NET Core project?

I am trying to learn and understand nuget and msbuild in .NET Core by examining and manually editing project files (.csproj in .NET Core 2.2).
So when I create WebApi project, the .csproj file looks like this:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Notice that there is no Version attribute specified for the first PackageReference.
Now if I specify it to be the latest stable version 2.2.3 like this:
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.3" />
I get build warning NETSDK1071 which says:
A PackageReference to 'Microsoft.AspNetCore.App' specified a Version
of 2.2.3. Specifying the version of this package is not recommended.
For more information, see https://aka.ms/sdkimplicitrefs
This warning is not shown when Version attribute is omitted so I was wondering how is nuget package Version resolved when not set explicitly?
Also, how does dotnet build knows which version of a nuget package is recommended with the current project settings?
From the link in the warning, you can learn that it is not a regular package, but Meta-package.
It's mean that this package depends on your TargetFramework, and this is mean that when you target to a specific framework that installed in your machine (as SDK), the package will be taken from the specific SDK.

Build error of ASP.NET Core - "...current settings, version 2.1.0-preview3-26411-06 would be used instead"

I've created a sample project using dotnet, but I get the following error when building the project:
error : The project was restored using Microsoft.NETCore.App version 2.1.0-rc1, but with current settings, version 2.1.0-preview3-26411-06 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore.
What's the problem? I'm using Visual Studio 2017 build 15.7.0.
I had a similar error message:
The project was restored using Microsoft.NETCore.App version 2.0.7, but with current settings, version 2.0.0 would be used instead. To resolve this issue, make sure the same settings are used for restore and for subsequent operations such as build or publish. Typically this issue can occur if the RuntimeIdentifier property is set during build or publish but not during restore
I added the RuntimeFrameworkVersion setting to the .csproj file, and it fixed an issue for me:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.7</RuntimeFrameworkVersion><!--here is the fix-->
</PropertyGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.7" />
</ItemGroup>
It seems Visual Studio is using different .NET Core versions for restore/build/publish.
To resolve this issue, you could add TargetLatestRuntimePatch attribute in the .csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>
For details, please see this page.
In my case, in the .csproj file I changed
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.5" />
</ItemGroup>
to:
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" />
</ItemGroup>
And it worked.
I’ve installed .NET SDK 2.2.0 and found out that this isn't the correct version and the correct one was renamed to 2.1.300 to be in sync with the .NET Core application whose the last version is 2.1.0. I installed 2.1.300 and everything runs correctly.
Just because you have the latest SDK installed doesn't mean you have the latest runtime installed. I'll never quite understand that.
Run dotnet --info.
I got the following (only the latest installed versions are shown here).
.NET Core SDKs installed:
2.1.300 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:d\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
So I installed 2.1.1 runtime, and now dotnet --info gives me 2.1.1 as well.
Oh and 2.1.3 actually is 2.1.1, but they had to increment it for some reason I don't fully understand about or care about.
I restarted Visual Studio, because it never seems to be able to keep versions in sync
I added the following to PropertyGroup in my .csproj file (unload project + edit)
netcoreapp2.1
2.1.1
Now I thought we didn't need to specify this this any more, and this .csproj file was just created brand new today and it didn't have a runtime version at all. Whatever we're supposed to be doing, this worked for me. I also found this massive thread about versioning with 2.1.1 which I skimmed over, but it seems there are complications with point releases right now, so maybe this specific version is necessary.
I ended up here because of this error:
error : The project was restored using Microsoft.NETCore.App version
2.1.1, but with current settings, version 2.1.0 would be used instead. To resolve this issue, make sure the same settings are used for
restore and for subsequent operations such as build or publish.
Typically this issue can occur if the RuntimeIdentifier property is
set during build or publish but not during restore.
Adding RuntimeFrameworkVersion was the specific fix for that that worked.
Unfortunately there isn't any linked article for this error message, which would be helpful.
Use:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<UserSecretsId>aspnet-...............245435</UserSecretsId>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.1" />
</ItemGroup>
</Project>
In my case the issue was fixed by ensuring I had two projects, with one depending on the other.
One project had a RuntimeIdentifier specified in the .csproj file, but the other did not. Once I ensured both had matching RuntimeIdentifiers, the problem was fixed.
The specific error I was getting was
error : NETSDK1061: The project was restored using Microsoft.NETCore.App version 2.0.5, but with current settings, version 2.1.1 would be used instead.
I had
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.0.5" />
</ItemGroup>```
further down the file. Once I removed this and did a clean, the project built successfully.
I have a somehow different solution, working for ASP.NET 2.1, as I had problems with both building and publishing processes:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion> --> fix publishing issues
<PlatformTarget>AnyCPU</PlatformTarget> --> fix publishing issues
</PropertyGroup>
<ItemGroup>
<PackageReference Update="Microsoft.NETCore.App" Version="2.1.0" /> --> fix building issues
<ProjectReference Include="..\PublicSonar.Monitor.Persistent.Json\PublicSonar.Monitor.Persistent.Json.csproj" />
</ItemGroup>
</Project>
I experienced the same:
The project was restored using Microsoft.NETCore.App version 2.1.2, but with current settings, version 2.1.0 would be used instead.
Removing the explicitly set --self-contained false from the dotnet publish command seemed to do the trick for us. It defaults to the same, so why it makes a difference, I have no idea.
This was with SDK version 2.1.400.

How do you publish a clickonce installer that includes .net installer and Auto-Update functionality?

I am using TeamCity for a continuous integration server and am deploying my application using a ClickOnce installer. I can get the installer to function and deploy my application but I cannot figure out how to include the installer for .net 4.5 if the computer does not already have it installed or how to enable the auto-update check feature in ClickOnce deployments. I am currently using the MSBuild file below to build my installer
<Project DefaultTargets="DoPublish" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<PropertyGroup>
<Version>$(BUILD_NUMBER)</Version>
<Install>true</Install>
<InstallFrom>Unc</InstallFrom>
<UpdateEnabled>true</UpdateEnabled>
<UpdateMode>Background</UpdateMode>
<ClickOnceBuildDirectory>$(MSBuildProjectDirectory)\MyProject\bin\$(Configuration)\app.publish</ClickOnceBuildDirectory>
<ClickOnceInstallDirectory>$(MSBuildProjectDirectory)\Publish</ClickOnceInstallDirectory>
<ClickOnceFinalLocation>$(env_PublishUrl)</ClickOnceFinalLocation>
</PropertyGroup>
<Target Name="DoPublish">
<RemoveDir Directories="$(ClickOnceInstallDirectory)" ContinueOnError="true" />
<MSBuild Projects="MyProject.sln" Targets="Clean;Build" Properties="ApplicationVersion=$(Version);Configuration=$(Configuration)"/>
<MSBuild Projects="MyProject\MyProject.csproj" Targets="Publish" Properties="ApplicationVersion=$(Version);Configuration=$(Configuration);InstallUrl=$(ClickOnceFinalLocation)" />
<MakeDir Directories="$(ClickOnceInstallDirectory)"/>
<Exec Command="xcopy /E $(ClickOnceBuildDirectory) $(ClickOnceInstallDirectory)" />
</Target>
</Project>
You can use a bootstrapper to handle prerequisites like checking for the .NET Framework. Check the Application Deployment Prerequisites MSDN article, especially the sections about bootstrapping with ClickOnce and MSBuild.
There are also 2 more MSDN articles that detail how to install ClickOnce prerequisites and Creating bootstrapper packages.
As for auto-updates, do you want to locate the auto-update functionality outside the application itself, i.e., in an installer vs. in the application? There are several ways to allow ClickOnce updates in your application, including auto-updates via the ClickOnce Deployment API.
A brief explanation of using ClickOnce Bootstrapper packages can be found in this existing Stackoverflow article. Though you're not using WiX here, you can also check this this WiX thread, which is useful because you see some of the steps that didn't work along the way. These examples show the use of the GenerateBootstrapper MSBuild task to create the bootstrapper for the ClickOnce installer. Note that in the examples at the above links, the "Path" in the GenerateBootstrapper task is set to a subfolder under a Windows SDK location. This can be changed to another location, as long as that location has the necessary prerequisite packages.
Below is an example in which the .NET 4.5 Framework is set as a prerequisite for the install. The parent directory structure for the .NET 4.5 prerequisite is specified by the $(MyPathToPrerequisitePackages) property.
The BootstrapperFile item in the below example specifies the .NET 4.5 Framework prerequisite package. The value ".NETFramework,Version=v4.5" comes from the product.xml file in the Bootstrapper\Packages\DotNetFX45 folder, and allows the GenerateBootstrapper task to correctly identify the .NET 4.5 prerequisite/bootstrapper package. The "ProductName" value is simply a friendly description of the package.
<PropertyGroup>
<MyPathToPrerequisitePackages>C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\Bootstrapper</MyPathToPrerequisitePackages>
</PropertyGroup>
<ItemGroup>
<BootstrapperFile Include=".NETFramework,Version=v4.5">
<ProductName>.NET Framework 4.5</ProductName>
</BootstrapperFile>
</ItemGroup>
<GenerateBootstrapper
ApplicationFile="$(MyAppAssembly).application"
ApplicationUrl="$(MyClickOnceAppUrl)"
ApplicationName="$(MyClickOnceAppName)"
BootstrapperItems="#(BootstrapperFile)"
Culture="en"
FallbackCulture="en-US"
CopyComponents="true"
Validate="false"
Path="$(MyPathToPrerequisitePackages)"
SupportUrl="$(MyAppSupportUrl)"
OutputPath="$(MyDesiredOutputPath)\" />
Just posted a response on 'https://stackoverflow.com/a/39610060/1345870':
Just struggled with this myself - I chose to commit the bootstrapper files to source control. It is possible to override the path to bootstrappers, just provide /p:GenerateBootstrapperSdkPath=.build\Bootstrapper
Then no need to modify registry - and the added benefit that the build is now self-contained.
Only "problem" is that I have to manually copy the Bootstrapper files into source control. In my case (VStudio2015), this meant copying the files from C:\Program Files (x86)\Microsoft Visual Studio 14.0\SDK\Bootstrapper