How to use nuget library SimpleHelpers.FileEncoding on c# on VScode - c#

dotnet add package SimpleHelpers.FileEncoding
SimpleHelpers.FileEncoding
dotnet run
it shows:
C:\Users\user\Downloads\c2\Program.cs(1,7): Error CS0246: The type or namespace name 'SimpleHelpers' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\user\Downloads\c2\c2.csproj]
Program.cs:
using SimpleHelpers.FileEncoding;
namespace c2;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
var encoding = FileEncoding.DetectFileEncoding (#"D:\b\big5\LanTingJiXu_big5.txt");
}
}
c2.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SimpleHelpers.FileEncoding" Version="1.4.0" />
</ItemGroup>
</Project>
update the error message.

It looks like this package was authored to use the content folder with a .cs.pp file transform that were previously rendered and copied to the project folder for projects using packages.config to reference NuGet packages.
This is no longer supported for SDK-style projects which use PackageReference. The package author would need to switch to (or add) contentFiles to support PackageReference or create a pre-built binary (.dll file).

Related

The type or namespace name 'Specflow_xxx_XUnitAssemblyFixture' could not be found (are you missing a using directive or an assembly reference?)

After I installed this nuget package in my specflow demo C# .NET Core 3.1 project, I got this error:
Severity Code Description Project File Line Suppression State
Error CS0246 The type or namespace name
'Specflow_Demo_XUnitAssemblyFixture' could not be found (are you
missing a using directive or an assembly
reference?) Specflow.Demo ...\Specflow.Demo\Features\LoggedInDiscount.feature.cs\LoggedInDiscount.feature 3 Active
This is my csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.22" />
<PackageReference Include="SpecFlow.xUnit" Version="3.9.22" />
<PackageReference Include="SpecRun.SpecFlow" Version="3.9.7" />
</ItemGroup>
</Project>
After I close all the files in Visual Studio and rebuild, I got another error:
There is an open issue with SpecFlow related to this: Type or namespace [TestNamespace]_XunitAssemblyFixture could not be found. Are you still able to run your test cases? The above link says its an intellisense only issue.
From a comment on the GitHub issue discussion:
The generated assemblyFixture file (e.g.: [TestNamespace]_XunitAssemblyFixture) can be found in the obj folder (obj\Debug\targetframework\xUnit.AssemblyHooks.cs).
We realized that this is IntelliSense related "issue" (IntelliSense of VisualStudio itself, not R#).
As you all noticed, the build was successful, but the error was still there. This is because the generated code behind file (*.feature.cs) is opened in your editor. If you close them, and build again, the error will disappear.
...
BTW there is an ongoing PR which will move the generated files to the obj folder, so this problem will disappear when it'll be merged.
I had a quick look through the types in the referenced nuget packages. None of them uses the naming style that you have there 'Specflow_Demo_XUnitAssemblyFixture' - and none of them has a type with a similar name.
So, as the error says, the type doesnt exist.

Why do .Net5 projects have a reference to Microsoft.VisualBasic?

The following code can be compiled and run, without having an explicit reference to a Microsoft.VisualBasic dll or package:
using Microsoft.VisualBasic;
Interaction.Beep(); // from Microsoft.VisualBasic
System.Console.WriteLine("Done");
Here the corresponding project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
Look under Dependencies > Frameworks in the Solution Explorer and you'll see Microsoft.NETCore.App listed. Expand that node and you'll see all the assemblies included in that framework, which includes Microsoft.CSharp, Microsoft.VisualBasic and Microsoft.VisualBasic.Core. That means that VB projects have a reference to Microsoft.CSharp as well.

Using MongoDB.Driver inside azure functions

I'm trying to use an azure function to upload data to a mongodb but I get an error saying "The type or namespace name 'MongoDB' could not be found (are you missing a using directive or an assembly reference?)". I have a function.proj file that has refs to the MongoDB.Driver package but that doesn't seem to be working. I tried using the #r sytax to import the package but thats not working either. I'm using version 3 of the azure funtion runtime. Can anybody point me in the right direction?
Contents of the function.proj file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver.Core" Version="2.11.3" />
<PackageReference Include="MongoDB.Driver" Version="2.11.3" />
<PackageReference Include="MongoDB.Bson" Version="2.11.3" />
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</ItemGroup>
Using directives
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;
using MongoDB.Driver;
using MongoDB.Bson;
Update:
Thanks for Ggd Hhdhd's working. Azure function can not install some package on azure when based on crx. The solution is to send related dll directly to the bin directory on azure. This is the doc:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#referencing-custom-assemblies
And this is the structure:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-csharp#folder-structure
Original Answer:
Please don't use C# script to do this.
Some package is not supported to install in C# script azure function on azure. I notice you install three package, but in fact, you just need to install MongoDB.Driver is ok. MongoDB.Driver is an integrated package that includes MongoDB.Driver.Core and MongoDB.Bson.
Problem is not from your code. The problem comes from just install the MongoDB.Driver package will broken the function.
By the way, the format of the function.proj should be like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.11.3" />
</ItemGroup>
</Project>
You miss the </Project>.
I try to find some package but didn't find.

Package's target is .NETCore but mine is .NETCoreApp

I want to add a package to my project, but it says:
error: Package PixivCS 0.4.4 is not compatible with net5.0 (.NETCoreApp,Version=v5.0). Package PixivCS 0.4.4 supports: netcore50 (.NETCore,Version=v5.0)
Then I tried to change the target framework using the properties option in VisualStudio, but the .NET 5.0 is the only option
screenshot
If change the <TargetFramework>net5.0</TargetFramework> in .csproj to <TargetFramework>netcore50</TargetFramework>
Error NETSDK1013 The TargetFramework value 'netcore50' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly. HelloWorld C:\Program Files\dotnet\sdk\5.0.100-preview.3.20216.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets 100
How can I change the framework of my project form net5.0 to netcore50 so I can use that package?
What's the difference between .NETCore and .NETCoreApp?
Update with new version. Please go here https://visualstudio.microsoft.com/downloads/ and update your VS. Then try to replace:
<TargetFramework>net5.0</TargetFramework>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>

How to add "System" as reference in my file csproj

I have this error:
The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference)
And my .csproj file contains:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
I created the project with the command "dotnet new console"
Would like to know if it is possible, how to generate this (not manually) but with the help of "dotnet"

Categories

Resources