'PublishAsync' missing in RabbitMq package - asp.net-core

I have the following code:
public async Task<IActionResult> Post([FromBody]CreateActivity command)
{
command.Id = Guid.NewGuid();
command.CreatedAt = DateTime.UtcNow;
await _busClient.PublishAsync(command);
return Accepted($"activities/{command.Id}");
}
It seems like 'PublishAsync' method is missing in RabbitMq. This is my .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0" />
<PackageReference Include="RawRabbit" Version="2.0.0-beta8" />
<PackageReference Include="RawRabbit.DependencyInjection.ServiceCollection" Version="2.0.0-beta8" />
<PackageReference Include="RawRabbit.Operations.Subscribe" Version="2.0.0-beta8" />
</ItemGroup>
</Project>
It is the same with all other stable versions.

Looking at the source code it seems that the PublishAsync method is defined as an extension method in the RawRabbit.Operations.Publish NuGet pacakge:
Enrich the BusClient with PublishAsync, used to perform a BasicPublish

Related

How to exclude folders from Visual Studio 2022 WebDeploy?

I don't manage to exclude certain folders from Visual Studio 2022 WebDeploy (publish to IIS).
There is a bunch of folders that I do not want to be published to my server (e.g. jquery, bootstrap-icons etc.).
I followed this post and ended up with a new xml file. The file is called [MyProjectName].wpp.targets.xml and it is located in the same folder as my [MyProjectName].csproj.
The file looks like this:
<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ExcludeFromPackageFolders
Include="wwwroot\lib\jquery;
wwwroot\lib\jquery-validate;
wwwroot\lib\jquery-validation-unobtrusive;
wwwroot\lib\jquery-ajax-unobtrusive;
wwwroot\lib\popper.js;
wwwroot\lib\bootstrap-icons">
</ExcludeFromPackageFolders>
</ItemGroup>
On my next Publish, however, all those folders (and included files) are still being copied to my server.
What am I doing wrong?
I am using Visual Studio Community 2022, V.17.1.5, with a .NET 6 application.
Edit your {project_name}.csproj file and add the following lines...
<ItemGroup>
<Folder Include="wwwroot\Files\" Exclude="Files\**\*" />
</ItemGroup>
With "wwwroot\Files" being the location of the folder with the files you want to exclude.
This can be anywhere inside your top level declaration.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.32" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.32" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.5" />
<PackageReference Include="System.Linq" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PCS.BusinessServices\PCS.BusinessServices.csproj" />
<ProjectReference Include="..\PCS.Common\PCS.Common.csproj" />
<ProjectReference Include="..\PCS.Data.Services\PCS.Data.Services.csproj" />
<ProjectReference Include="..\PCS.Data\PCS.Data.csproj" />
<ProjectReference Include="..\PCS.Encryption\PCS.Encryption.csproj" />
<ProjectReference Include="..\PCS.PdfEngine\PCS.PdfEngine.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="wwwroot\Files\" Exclude="Files\**\*" />
</ItemGroup>
</Project>

IWebHostEnvironment .Net 5 not found

I am using .Net 5 class library project and here are my refrences. I am using
using Microsoft.AspNetCore.Hosting; But I cannot find IWebHostEnvironment. What wrong am I doing ?
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.12.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
<PackageReference Include="Microsoft.Graph" Version="3.19.0" />
<PackageReference Include="Microsoft.Graph.Core" Version="1.22.0" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.8" />
<PackageReference Include="Microsoft.ReportViewer.WebForms" Version="10.0.40219.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
<PackageReference Include="System.Runtime" Version="4.3.1" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.2" />
<PackageReference Include="System.ServiceModel.Http" Version="4.8.1" />
<PackageReference Include="System.ServiceModel.Primitives" Version="4.8.1" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.ServiceModel" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services" />
</ItemGroup>
</Project>
On .Net5.0, IWebHostEnvironment has been replaced by IHostEnvironment
Make sure you have the package Microsoft.Extensions.Hosting installed and the following import on the top of the file.
using Microsoft.Extensions.Hosting;
More information can be seen at aspnetcore github discussion
IWebHostEnvironment is included in the Microsoft.AspNetCore.Hosting package, you simply need to add it as a reference to your project by right clicking on your project file and selecting 'Manage Nuget Packages' then searching for Microsoft.AspNetCore.Hosting and add it.
If you've already added it and it still isn't working, try cleaning your project.

MSBuild not assigning version number

I am using the following command in azure pipelines to apply a PackageVersion to the outputted DLLs. The PackageVersion is not coming through and I can't tell if it's because another configuration is overwritting it or something else. The PackageVersion (the AssemblyInfoVersion in c# is always the default 1.0.0)
- task: MSBuild#1
displayName: 'Build solution eCommerceAPI.sln'
inputs:
solution: eCommerceAPI.sln
msbuildArchitecture: x64
configuration: Release
msbuildArguments: '/p:DebugType=none /p:DebugSymbols=false /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:DeployAsIisApp=False /p:DeployIisAppPath="Default Web Site/eCommerceAPI" /p:PackageLocation=$(Build.ArtifactStagingDirectory)"\eCommerceAPI.zip" /p:PackageVersion=$(Build.BuildNumber)'
Including the csproj as requested:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web">
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.5" />
<PackageReference Include="System.Threading.Tasks" Version="4.3.0" />
<PackageReference Include="System.Threading" Version="4.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="4.1.1" />
<PackageReference Include="JWT" Version="6.1.4" />
<PackageReference Include="AutoMapper" Version="9.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.5" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<DocumentationFile>$(MSBuildThisFileName).xml</DocumentationFile>
<UserSecretsId>11111111-1111-1111-1111-111111111111</UserSecretsId>
</PropertyGroup>
</Project>
The PackageVersion does not update the versions associated with the assemblies but the Version parameter will assign the version to all assemblies.

.csproj bug in Asp .NET Core MVC

I have wanted to create new table in my database (SQLite), so I created new Model and used it in ApplicationDbContext class like this:
public DbSet<AppUser> AppUsers { get; set; }
public DbSet<Report> Reports { get; set; }
Then executed the command later:
dotnet ef migrations add Report
I can see migration file.
In Startup.cs file I have:
services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));
services.AddDbContext<AppIdentityDbContext>(options => options.UseSqlServer(connectionString));
In EFRepository.cs:
public IQueryable<AppUser> AppUsers
=> ctx.AppUsers;
public IQueryable<Report> Reports => ctx.Reports;
After this somehow suddenly I received many errors connected with this file ( .csproj):
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AssemblyName>Mushrooms</AssemblyName>
<RootNamespace>Mushrooms</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
</ItemGroup>
</Project>
I checked dotnet --info command, but I can't see incompatibility.
Three of the errors:
Invalid markup declaration '<'
Invalid markup declaration '
Invalid token "" at root level of document.
and many more in every line of this file.
This errors have occured when system was starting up.
I am using Asp .NET Core MVC 3.0.0.
Before this everything was working fine, any suggestions?
I try to create blank .net core 3.0 project and this csproj file is working fine
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.0" />
</ItemGroup>
</Project>
Try to check your project extension file should be .csproj

How to assign the version of a specific PackageReference to a property

I am trying to get the version of a specific package that is referenced through the PackageReference, so that I can reference a tool that comes inside one of those packages. I am able to write the version using a Message task:
<Message Importance="High" Text="#(PackageReference->%(PackageReference.Version))" Condition="'%(PackageReference.Identity)' == 'Google.Protobuf.Tools'" />
How can I retrieve that value inside a property?
The relevant parts from my csproj looks like this:
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.5.0" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.5.0" />
<PackageReference Include="Grpc" Version="1.8.0" />
<PackageReference Include="Grpc.Tools" Version="1.8.0" />
</ItemGroup>
<PropertyGroup>
<ProtobufCompiler>$(UserProfile)/.nuget/packages/Google.Protobuf.Tools/3.5.0/tools/windows_x64/protoc.exe</ProtobufCompiler>
<GrpcCSharpPlugin>$(UserProfile)/.nuget/packages/Grpc.Tools/1.8.0/tools/windows_x64/grpc_csharp_plugin.exe</GrpcCSharpPlugin>
</PropertyGroup>
I found that I can use the CreateProperty task for that:
<CreateProperty Value="%(PackageReference.Version)" Condition="%(PackageReference.Identity) == 'Google.Protobuf.Tools'">
<Output TaskParameter="Value" PropertyName="GoogleProtobufToolsVersion" />
</CreateProperty>
Latest Grps.Tools calls proto compiler during the build.
<ItemGroup>
<PackageReference Include="Grpc.Tools" Version="2.31.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Protobuf Include="my.proto" GrpcServices="None">
</Protobuf>