Console Application: Program does not contain a static 'Main' method suitable for an entry point - While Main exists - .net-core

My .NET 5 project's Program.cs looks like this:
using System;
namespace XmlGenerator.Cli
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine(("Boo!!!"));
}
}
}
And my project file looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Program.cs" />
</ItemGroup>
<ItemGroup>
<None Remove="Master.xml" />
</ItemGroup>
<ItemGroup>
<Content Include="Program.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Resource Include="Master.xml" />
</ItemGroup>
</Project>
When I try and run the app with F5, I get the following error:
CS5001 Program does not contain a static 'Main' method suitable for an entry point
I certainly does contain a Main, so what could be wrong?

My solution was to delete all the ItemGroup elements from the project file, leaving just:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
</Project>

Related

Exclude target framework from NuGet package

How can i exclude specific target framework from nuspec (NuGet package) generation?
This is my csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net5.0-windows</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'net5.0-windows'">
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
dotnet pack command generates NuGet package that contains all target frameworks not only netstandard2.0 and net5.0
Generated nuspec:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ExampleLibrary</id>
<version>1.0.0</version>
<authors>ExampleLibrary</authors>
<description>Package Description</description>
<dependencies>
<group targetFramework="net5.0" />
<group targetFramework="net5.0-windows7.0" />
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net5.0-windows7.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<GenerateNuspecDependsOn>$(GenerateNuspecDependsOn);_ExcludeTargetFramework;_ExcludeTargetFrameworkDependency</GenerateNuspecDependsOn>
</PropertyGroup>
<Target Name="_ExcludeTargetFramework" AfterTargets="_GetTargetFrameworksOutput" BeforeTargets="_WalkEachTargetPerFramework">
<ItemGroup>
<_TargetFrameworks Remove="net5.0-windows7.0" />
</ItemGroup>
</Target>
<Target Name="_ExcludeTargetFrameworkDependency" AfterTargets="_WalkEachTargetPerFramework" BeforeTargets="GenerateNuspec">
<ItemGroup>
<_FrameworksWithSuppressedDependencies Include="net5.0-windows7.0" />
</ItemGroup>
</Target>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>ExampleLibrary</id>
<version>1.0.0</version>
<authors>ExampleLibrary</authors>
<description>Package Description</description>
<dependencies>
<group targetFramework="net5.0" />
<group targetFramework=".NETStandard2.0" />
</dependencies>
</metadata>
</package>
Remove all the dependencies (including TargetFramework)
In case you want to remove all dependencies (ie all target frameworks), the above solution won't work. Build will fail with the following error:
error MSB4044: The "ResolvePackageAssets" task was not given a value for the required parameter "TargetFramework".
Easy way
In case you just want to remove all dependencies, you can use the SuppressDependenciesWhenPacking property.
<PropertyGroup>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
</PropertyGroup>
Full control of Nuspec
Otherwise, if you want to have a full control on the content of Nuspec after a first pass of generation, you can use a variation of this:
<?xml version="1.0" encoding="utf-8"?>
<Project>
<UsingTask
TaskName="RemoveDependencies"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<Nuspec ParameterType="System.String" Required="true"/>
</ParameterGroup>
<Task>
<Reference Include="System.Xml"/>
<Reference Include="System.Xml.Linq"/>
<Using Namespace="System"/>
<Using Namespace="System.IO"/>
<Using Namespace="System.Xml.Linq"/>
<Code Type="Fragment" Language="cs">
<!-- Modify XML of the NuSpec -->
<![CDATA[
XElement doc = XElement.Load(Nuspec);
var dependenciesElement = doc.Descendants(XName.Get("dependencies", "http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd")).FirstOrDefault();
if (dependenciesElement != null)
{
dependenciesElement.Remove();
}
using (var textWriter = File.CreateText(Nuspec))
{
doc.Save(textWriter);
}]]>
</Code>
</Task>
</UsingTask>
<!-- From https://stackoverflow.com/questions/53762903/how-to-inject-a-custom-dependency-in-an-msbuild-nuget-pack-generated-nuspec -->
<!-- Disable nupkg generation before running pack -->
<Target Name="__DisablePacking" BeforeTargets="GenerateNuspec" Condition="$(NuspecFile) == '' And $(IsPackable) != 'false'">
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>false</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
</Target>
<!-- Remove .Net Standard 2.0 dependency as it's a native package -->
<!-- Modify the generated nuspec file and rerun the pack target -->
<Target Name="__ExcludeTargetFrameworkDependency" AfterTargets="Pack" Condition="$(NuspecFile) == '' And $(IsPackable) != 'false'">
<!-- Get the nuspec file name -->
<PropertyGroup>
<_NugetPackOutputAsProperty>#(NuGetPackOutput)</_NugetPackOutputAsProperty>
</PropertyGroup>
<ItemGroup>
<_NugetPackOutputAsItem Remove="#(_NugetPackOutputAsItem)"/>
<_NugetPackOutputAsItem Include="$(_NugetPackOutputAsProperty.Split(';'))" />
</ItemGroup>
<PropertyGroup>
<__NuspecFileName>%(_NugetPackOutputAsItem.Identity)</__NuspecFileName>
</PropertyGroup>
<Message Importance="High" Text="Remove Dependencies from $(__NuspecFileName)" />
<RemoveDependencies Nuspec="$(__NuspecFileName)" />
<!-- Invoke the Pack target again with packing enabled -->
<PropertyGroup>
<ContinuePackingAfterGeneratingNuspec>true</ContinuePackingAfterGeneratingNuspec>
</PropertyGroup>
<MsBuild
Projects="$(MSBuildProjectFullPath)"
Targets="Pack"
Properties="NuspecFile=$(__NuspecFileName);NoPackageAnalysis=true">
</MsBuild>
</Target>
</Project>
Notes:
GenerateNuspec target is doing both generation and packing. To disable packing after nuspec generation, we can use the ContinuePackingAfterGeneratingNuspec property.
Pack target is invoked twice (once by the user) and the second time with the system after first pack.
__ExcludeTargetFrameworkDependency rely on the Nuspec File value to be empty to execute on the first pack and to not execute on the second run. It obviously won't work if a Nuspec file is provided for the first run (with NuspecFile property).
Note the usage of And $(IsPackable) != 'false' to avoid invoking the target on test projects.
All NuGet targets like GenerateNuspec are located in C:\Program Files\dotnet\sdk\6.0.308\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets
All NuGet tasks for .NET 6, like PackTask, are located in C:\Program Files\dotnet\sdk\6.0.308\Sdks\NuGet.Build.Tasks.Pack\Desktop\NuGet.Build.Tasks.Pack.dll

Could not load type 'Context' from assembly 'Microsoft.AspNetCore.Hosting'

Running my integration tests for some controllers, I get this exception:
Error Message:
System.TypeLoadException : Could not load type 'Context' from assembly
'Microsoft.AspNetCore.Hosting, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
I've already checked this but not helpful
Could not load type 'Context' from assembly 'Microsoft.AspNetCore.Hosting, Version=3.0.0.0
Here's the list of dependencies in unit test proj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Content Include="..\..\src\MyMicroserviceActio.Api\appsettings.json" Link="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="4.19.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.7.142" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\MyMicroserviceActio.Api\MyMicroserviceActio.Api.csproj" />
</ItemGroup>
</Project>
And here's an example of a test case:
private readonly TestServer _server;
private readonly HttpClient _client;
public HomeControllerTests()
{
_server = new TestServer(WebHost.CreateDefaultBuilder()
.UseStartup<Startup>());
_client = _server.CreateClient();
}
[Fact]
public async Task home_controller_get_should_return_string_content()
{
var response = await _client.GetAsync("/");
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
content.Should().BeEquivalentTo("Hello from MyMicroserviceActio API!");
}
The whole project is github
You need to bump Microsoft.AspNetCore.TestHost to a compatible 3.x version (PR submitted).

Microsoft.NET.Sdk.Web missing Web menu (ASP.NET)

I try to convert old ASP.NET MVC 5 (349C5851-65DF-11DA-9384-00065B846F21) projects to new format with Microsoft.NET.Sdk.Web.
One main difference is the missing Web menu under Project > Properties. How could I configure these settings in the new format?
Old ASP.NET Project:
New Microsoft.NET.Sdk.Web Project:
File Content of Microsoft.NET.Sdk.Web Project (vbproj)
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<Deterministic>false</Deterministic>
<TargetFramework>net48</TargetFramework>
<OutputPath>$(SolutionDir)bin\ptc\$(Configuration)\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OptionStrict>On</OptionStrict>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<OutputType>Library</OutputType>
<UseIISExpress>true</UseIISExpress>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Web.ApplicationServices" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.7" />
</ItemGroup>
</Project>

NopCommerce Plugins built within custom plugin

I am using Nopcommerce 4.2 and trying to create a custom Plugin.
At runtime I get the error:
System.Exception: 'A plugin with 'DiscountRequirement.MustBeAssignedToCustomerRole' system name is already defined
When I go to Nop.Web/Plugins, I can see all the plugins that have been built - including mine. When I look in my custom plugin, I can see a folder folder called Plugins, this contains all the other plugins that have been built.
I have looked at my csproj and compared it against nop default plugins and cannot work out why mine builds all the plugins again.
to be clear the structure that is being created is:
Nop.Web
Plugins/
--DiscountRules.CustomerRoles
--ExchangeRate.EcbExchange
--...Other plugins...
--My.Plugin/
----App_Data
----Areas
----Plugins/
-----DiscountRules.CustomerRoles
-----ExchangeRate.EcbExchange
-----...Other plugins...
my project file
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<OutputPath>..\..\Presentation\Nop.Web\Plugins\Widgets.MostViewedProducts</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<Compile Remove="Domain\**" />
<Content Remove="Domain\**" />
<EmbeddedResource Remove="Domain\**" />
<None Remove="Domain\**" />
</ItemGroup>
<ItemGroup>
<None Remove="logo.jpg" />
<None Remove="plugin.json" />
</ItemGroup>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Content Include="logo.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="plugin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\Create.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\Edit.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\List.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProductAttribute\_CreateOrUpdate.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\Create.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\Edit.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\List.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\ProductAttributeCatalogCreatePopup.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\ProductAttributeMappingCreate.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\ProductAttributeMappingEdit.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.Attributes.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.Info.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdate.SEO.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdateProductAttributeMapping.Catalog.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdateProductAttributeMapping.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\BuilderProduct\_CreateOrUpdateProductAttributeMapping.Info.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\ProductBuilder\Configure.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
<Content Update="Areas\Admin\Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\AttributeMappingProduct.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\Details.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\ProductDetails.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\_CatalogSelectors.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\BuilderProduct\_ProductBox.ProductBuilder.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Update="Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>$(IncludeRazorContentInPack)</Pack>
</Content>
</ItemGroup>
<ItemGroup>
<Folder Include="Areas\Admin\Controllers\" />
<Folder Include="Areas\Admin\Extensions\" />
<Folder Include="Areas\Admin\Factories\" />
<Folder Include="Areas\Admin\Infrastructure\" />
<Folder Include="Areas\Admin\Models\" />
<Folder Include="Areas\Admin\Views\" />
<Folder Include="Controllers\" />
<Folder Include="Extensions\" />
<Folder Include="Factories\" />
<Folder Include="Models\" />
</ItemGroup>
<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" />
</ItemGroup>
<ItemGroup>
<None Update="Views\Shared\Components\Default.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Views\_ViewImports.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</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>
</Project>
EDIT
Plugin.json
{
"InstalledPluginNames": [
"Widgets.GoogleAnalytics",
"Widgets.NivoSlider",
"ExternalAuth.Facebook",
"Misc.Cards",
"Payments.PayPalSmartPaymentButtons",
"Payments.PayPalStandard",
"Catalog.SkipToProduct"
],
"PluginNamesToUninstall": [],
"PluginNamesToDelete": [
"DiscountRequirement.MustBeAssignedToCustomerRole",
"CurrencyExchange.ECB",
"Misc.SendinBlue",
"Payments.CheckMoneyOrder",
"Payments.Manual",
"Payments.Qualpay",
"Payments.Square",
"Pickup.PickupInStore",
"Shipping.FixedByWeightByTotal",
"Shipping.UPS",
"Tax.Avalara",
"Tax.FixedOrByCountryStateZip"
],
"PluginNamesToInstall": []
}
the problem might be a reference, because when you add the reference DiscountRequirement.MustBeAssignedToCustomerRole to another plugin you need to put in the property Copylocal = false.
There are a few places that are having the error. Can't give an answer without checking such as plugin.json, dependencyregister.cs, plugin.cs,etc..
But when you familiar with it you can find your own way to speed up
your developments.
tip: This is the easiest way if you are still getting any issue with your plugin.
Just take a copy of small original plugin such as 'Nop.Plugin.Payments.Qualpay,Square,SendinBlue' and rename then edit .proj file set output folder.
remove all the unnecessary classes, files, and folders except 'DependencyRegistrar.cs,RouteProvider.cs,plugin.json,StartUpPlugin.cs'
change the namespaces of remaining files and remove unnecessary codes.
In plugin.json "SupportedVersions": [ "4.20" ] is a must value
build and clear all the errors.
It should appear on 'Configuration > Local Configuration'
tip: This is the my project building best practice when I'm getting references errors
Clean the solution
go to ~/API/Presentation/Nop.Web/Plugins folder and remove all the build folders.
Right-click on 'Libraries' folder and build it.
Right-click on 'Presentation' folder and build it.
Right-click on 'Plugins' folder and build it.
Good luck..!!
you can refer below as a template
plugin.json ("SupportedVersions": [ "4.20" ] is a must value) otherwise plugin service won't pick your plugin
{
"Group": "Plugin group name",
"FriendlyName": "Elastic Search",
"SystemName": "Custom.Plugin.ElasticSearch",
"Version": "1.56",
"SupportedVersions": [ "4.20" ],
"Author": "Isanka Thalagala",
"DisplayOrder": 27,
"FileName": "Custom.Plugin.ElasticSearch.dll",
"Description": "This plugin provice ilastic search"
}
DependencyRegistrar.cs class
public class DependencyRegistrar : IDependencyRegistrar
{
/// <summary>
/// Register services and interfaces
/// </summary>
/// <param name="builder">Container builder</param>
/// <param name="typeFinder">Type finder</param>
/// <param name="config">Config</param>
public virtual void Register(ContainerBuilder builder, ITypeFinder typeFinder, NopConfig config)
{
//register service manager
builder.RegisterType<SearchFilterService>().As<ISearchFilterService>().InstancePerLifetimeScope();
builder.RegisterType<ElasticSearchService>().As<IElasticSearchService>().InstancePerLifetimeScope();
}
/// <summary>
/// Gets order of this dependency registrar implementation
/// </summary>
public int Order => 1;
}
ElasticSearchPlugin.cs
public class ElasticSearchPlugin : BasePlugin
{
#region Ctor
public ElasticSearchPlugin()
{
}
#endregion
#region Methods
/// <summary>
/// Install the plugin
/// </summary>
public override void Install()
{
base.Install();
}
/// <summary>
/// Uninstall the plugin
/// </summary>
public override void Uninstall()
{
base.Uninstall();
}
#endregion
/// <summary>
/// Gets a value indicating whether to hide this plugin on the widget list page in the admin area
/// </summary>
public bool HideInWidgetList => true;
}
Please clear your bin and delete all of the plugin under this "Nop.Web -> Plugins" folder once. This works for me.
Thanks

Blazor Core Hosted - all Components in Razor Class Library Project are being printed as HTML on the page

I haven't been able to find the keywords for a similar issue, so I'm posting a new one.
The project was working fine and suddenly the issue described below happened. I was only editing some Razor files from the Razor Class Library, so I was unable to trace it back to any code modification I made.
The Issue:
I have the following project structure:
The Client, Server and Shared are projects that were initially created by the Blazor Template in the NET Core 3.0. DesktopClient is a similar Blazor project with ElectronNET and the issue is also happening on the component over there.The SharedLibrary project is the project where the components common to all projects are placed and where the root of the issue is apparently coming from.
The SharedLibrary is referenced on the Client project so I can access the components in the Client project.
What happened is that suddenly the components from the Razor Class Library stopped being "compiled" and all "#" are being printed as Raw HTML like the button for the "Counter 2":
[]
Notice as how there are 3 buttons on the image. The first one is in the base Razor page and is being compiled correctly. Second one is from the SharedLibrary project and is not being compiled apparently as the "#" tag is not being replaced. And the third button is from a Component in the Client project(same project as the base Razor page) and is also working correctly.
So the issue is that the SharedLibrary Razor files are not being "compiled".
What I've tried:
Remove and add reference from project;
Clean and rebuild solution;
Update packages;
Checked .csproj to see if I could find anything wrong/missing (not experienced on this file, so might have missed something).
Created a new Blazor Core Hosted project and added a Razor Class Library with the same setup as this demo. It worked fine, so the problem in on this project. Dependencies and ".csproj" files seem very similar.
The code:
.csproj for Client project:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazor.Extensions.SignalR" Version="0.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\SharedLibrary\SharedLibrary.csproj" />
<ProjectReference Include="..\Shared\ServerAPI.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\SharedLibrary\Content\styles\font\**\*.*">
<Link>wwwroot\styles\font\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\SharedLibrary\Content\images\system\*.*">
<Link>wwwroot\images\system\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="..\..\SharedLibrary\Content\images\social\brands\*.*">
<Link>wwwroot\images\social\brands\%(RecursiveDir)%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Compile Remove="bin\**" />
<Content Remove="bin\**" />
<EmbeddedResource Remove="bin\**" />
<None Remove="bin\**" />
<Content Remove="compilerconfig.json" />
</ItemGroup>
<ItemGroup>
<_ContentIncludedByDefault Remove="compilerconfig.json" />
<_ContentIncludedByDefault Remove="wwwroot\styles\main.css" />
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
<Folder Include="Services\" />
<Folder Include="wwwroot\images\system\" />
<Folder Include="wwwroot\scripts\" />
</ItemGroup>
<ItemGroup>
<None Include="compilerconfig.json" />
</ItemGroup>
<ItemGroup>
<Content Update="wwwroot\styles\main.css">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
</Content>
</ItemGroup>
<Target Name="CopyLinkedContentFiles" BeforeTargets="Build">
<Copy SourceFiles="%(Content.Identity)" DestinationFiles="%(Content.Link)" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" Condition="'%(Content.Link)' != ''" />
</Target>
</Project>
.csproj for SharedLibrary
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>true</IsPackable>
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
<LangVersion>8.0</LangVersion>
<Nullable>enable</Nullable>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Blazor.Extensions.SignalR" Version="0.4.0" />
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview9.19465.2" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview9.19465.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Content\images\social\brands\" />
<Folder Include="Core\Login\" />
<Folder Include="Core\Login\OAuth2\" />
<Folder Include="Services\" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources\Languages\en-US.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
<DependentUpon>en-US.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Resources\Languages\en-US.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>en-US.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
</Project>
Index.razor
#page "/"
#using ServerAPI.Client.Components
#using SharedLibrary.Components.User
<h1>Counter</h1>
<p>Current count: #currentCount</p>
<button class="btn btn-primary" #onclick="IncrementCount">Click me</button>
#code {
int currentCount = 0;
void IncrementCount()
{
currentCount++;
}
}
<SocialWithFormLoginComponent />
<Counter />
SocialWithFormLoginComponent.razor in SharedLibrary project
<h1>Counter 2</h1>
<p>Current count 2: #currentCount2</p>
<button class="btn btn-primary" #onclick="IncrementCount2">Click me 2</button>
#code {
int currentCount2 = 0;
void IncrementCount2()
{
currentCount2++;
StateHasChanged();
Console.WriteLine("Hello world!");
}
}
Counter.razor in Client project
<h1>Counter 3</h1>
<p>Current count 3: #currentCount3</p>
<button class="btn btn-primary" #onclick="IncrementCount3">Click me 3</button>
#code {
int currentCount3 = 0;
void IncrementCount3()
{
currentCount3++;
StateHasChanged();
Console.WriteLine("Hello world!");
}
}
Final comments
As you can see the code is very simple for my troubleshooting, however the project is not, so re-creating would be a lot of work.
Any suggestions I might try? I'm really confused here.
Thanks in advance!
Update with solution:
Turns out, as #dani hererra posted, I was missing "_Imports.razor" in the folder on my components from the attached Razor Class library like so:
Check Microsoft.AspNetCore.Components.Web is listed on _Imports.razor:
#using System.Net.Http
#using Microsoft.AspNetCore.Authorization
#using Microsoft.AspNetCore.Components.Authorization
#using Microsoft.AspNetCore.Components.Forms
#using Microsoft.AspNetCore.Components.Routing
#using Microsoft.AspNetCore.Components.Web //<-----
#using Microsoft.JSInterop
#using _your_namespace_
#using _your_namespace_.Shared

Resources