NuGet Pack -Build does not seem to understand c# 6.0 - c#

I have just went through one of my projects and used a bunch of the new c# 6 features like the null propagation operator handler?.Invoke(null, e), which builds in Visual Studio. However, when I run my script to publish out the NuGet packages, I get compilation errors saying:
EventName.cs(14,66): error CS1056: Unexpected character '$'
EventName.cs(69,68): error CS1519: Invalid token '=' in class, struct, or interface member declaration
EventName.cs(69,74): error CS1520: Method must have a return type
It would appear NuGet is using an older version of the compiler, but I was wondering if anyone knew a work around or configuration that could be set to resolve the issue.

Looks like you have also found this bug in the Nuget which is still not resolved:
https://github.com/NuGet/Home/issues/1107
You can use the following workaround:
Modify the script to build your project using correct version of MSBuild - just call MSBuild.exe yourself, supply the path to the csproj or sln file and build your project in a correct configuration yourself.
Create a nuspec file that describes your package (https://docs.nuget.org/create/nuspec-reference). You can use the Nuget Package Explorer app. Use DLLs produced in step 1.
Use nuget pack mypackage.nuspec to build the package.

Related

error MSB3823: Non-string resources require the property GenerateResourceUsePreserializedResources to be set to true

Hello everyone I got an error and I`m trying to solve it I found some similar source but could not solve my problem. Similar problem like here.
I compile my project .csproj file using .bat file actually it is .batch file from cmd. But I got this error:
error MSB3823: Non-string resources require the property GenerateResourceUsePreserializedResources to be set to true. [C:\Users\rmrud\source\Workspaces\Workspace2\HAL9\v3_07\Test\Test\Test.csproj]
and also I got this:
error MSB3822: Non-string resources require the
System.Resources.Extensions assembly at runtime, but it was not found in this project's references. [C:\Users\rmrud\source\Workspaces\Workspace2\HAL9\
v3_07\Test\Test\Test.csproj]
I also did this run this in cmd choco install visualstudio2019-workload-netcoretools.
I edited my .csproj file add these xml node in your xxx.csproj file:
<PropertyGroup>
<GenerateResourceMSBuildArchitecture>
CurrentArchitecture
</GenerateResourceMSBuildArchitecture>
<GenerateResourceMSBuildRuntime>
CurrentRuntime
</GenerateResourceMSBuildRuntime>
</PropertyGroup>
then again I compile using bat file from cmd but still got build error. How to overcome this thanks in advance. Please Note that in my machine I'm using .NET framework version 4.8 and .Net core 5
Please add System.Resources.Extensions NuGet package into an appropriate project.

I got an error when I'm trying to build my project using Cake

When I try to build I getting the follow error. Why Cake doesn't build my project?
What should I do? Does anyone know what need to do?
The 'addin' directive is attempting to install the 'Cake.Powershell' package
without specifying a package version number.
More information on this can be found at https://cakebuild.net/docs/tutorials/pinning-cake-version
It's not recommended, but you can explicitly override this warning
by configuring the Skip Package Version Check setting to true
(i.e. command line parameter "--settings_skippackageversioncheck=true",
environment variable "CAKE_SETTINGS_SKIPPACKAGEVERSIONCHECK=true",
read more about configuration at https://cakebuild.net/docs/fundamentals/configuration)
Error: One or more errors occurred.
Object reference not set to an instance of an object.
Process terminated with code 1.
Cake: https://cakebuild.net/
You should check which version of the package is the latest on NuGet
https://www.nuget.org/packages/Cake.Powershell
When writing this it's 0.4.8
Then in your addin directive you should adjust so it includes version i.e. if you now have
#addin nuget:?package=Cake.Powershell
or
#addin "Cake.Powershell"
You should change that to
#addin nuget:?package=Cake.Powershell&version=0.4.8
Pinning version ensures reproducible builds as you know you'll be using same version of dependencies each build.
If you go to the url in the error messsage ( https://cakebuild.net/docs/tutorials/pinning-cake-version ) you'll find more info about this.
The Object reference not set to an instance of an object. is hard to know the exact cause of, but running Cake with diagnostic verbosity would provide more detail. You achieve this by adding the verbosity parameter.
--verbosity=Diagnostic
If it's addin releated you could deleting the tools folder, by default it's located next the script your executing.

Issue with nuget package Xamarin.Firebase.iOS.CloudMessaging 3.1.2

I get many error messages if I install the Xamarin.Firebase.iOS.CloudMessaging 3.1.2 nuget package.
Error: linker command failed with exit code 1 (use -v to see invocation)
Error MT5210: Native linking failed, undefined symbol: _FIRLogBasic. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
Error MT5211: Native linking failed, undefined Objective-C class:
FIROptions. The symbol '_OBJC_CLASS_$_FIROptions' could not be found
in any of the libraries or frameworks linked with your application.
Error MT5211: Native linking failed, undefined Objective-C class:
GULAppEnvironmentUtil. The symbol
'_OBJC_CLASS_$_GULAppEnvironmentUtil' could not be found in any of the
libraries or frameworks linked with your application.
Error MT5201: Native linking failed. Please review the build log and
the user flags provided to gcc: -ObjC
Error MT5202: Native linking failed. Please review the build log.
I tried uninstalling and reinstalling the nuget package but I still get the same errors.
I use Visual Studio Community for Mac 8.1.5 (build 9).
I need Xamarin.Firebase.iOS.CloudMessaging because I follow this tutorial: https://www.robbiecode.com/setup-push-notifications-with-firebase-in-xamarin-forms-for-ios/
What is wrong with my project? What can I do?
The following two projects are in my solution:
InapppurchaseTest.iOS, MonoGame.Framework.iOS (develop)
Well, this is a well-known issue with Firebase and Xamarin, what basically happens here is the old bin and obj files while interacting with the new data override some existing files that are needed by iOS to synthesize the IPA while deployment and hence ends up throwing linking RELATED errors, follow the below steps and it will clear this mess.
Clean bin and obj
Delete the builds in the following path of your MAC machine - ~/Library/Caches/Xamarin/mtbs/builds/ProjNAME where 'ProjName' is the name of the project you are currently working on
Once you are done with both the above steps add the Xamarin.Firebase.iOS.CloudMessaging package and change linker setting to Don't Link (this is for the time being)
After installing these packages see to it that you build your project dependency wise which means PCL'S and .Net standards first then the native iOS project.
Clean bin and obj again if it does not work for the first build...
This should solve your issues in case it does not repeat the above procedure.
EDIT
If you check the GitHub comment by SotoiGhost here, it says adding the below line anywhere in your project should solve this issue...
var foo = Firebase.Core.Configuration.SharedInstance;
Feel free to get back in case of issues
Good luck!

Could Not Load Type From Assembly on unused package version

I have a C# project that I just pulled down from version control on a new machine. I have all the dependencies installed in the project and when I try to run it I get to my dependency injection initialization (ninject) an System.TypeLoadException error on an internal library. The error says that it cannot load version 5.3.1.0 of the library, but I am not using that version. In my Web.config I am pointing to 5.4.5.0 and in my machine config I am pointing to version 4.9.1.0 - neither of which the error mentions. I search the project for the version that the error mentions and get nothing as well.
Is there anywhere else for me to look for this reference?

Why am I getting error CS0246: The type or namespace name could not be found?

I am using Snarl C# API to send notifications to snarl.
Now I have saved the content of above url in a file named SnarlNetwork.cs and the content of my test.cs file are:
using SnarlNetworkProtocol;
using System;
class test
{
public static void Main(String[] args)
{
SNP snarl_object = new SNP();
string hostname = "localhost";
string hostport = "9887";
string appName = "Spotify";
bool val = snarl_object.register(hostname, hostport, appName);
if (val == true)
{
string title = "hello";
string message = "world";
string timeout = "5";
bool newval = snarl_object.notify(hostname, hostport, appName, null, title, message, timeout);
if (newval == true)
{
Console.WriteLine("sucessfull");
}
}
}
}
Now when I try to compile my test.cs file using csc test.cs I get the following error:
C:\Users\Noob\csharp>csc test.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.4926
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.
test.cs(1,7): error CS0246: The type or namespace name 'SnarlNetworkProtocol' could not be found (are you missing a using directive or an assembly reference?)
So, what am I doing wrong here because according to me I am not missing any using directive.
I was using .NET Framework 4.5 but my new library had .NET Framework 4.5.2 and I got the same issue when I tried to build. I solved it by updating my project from 4.5 to 4.5.2 (same as my library).
On the Solution Explorer tab right click and select Properties
Resolve this issue by updating the Target Framework in the project application settings.
For instance, In my case the project was compiling with .net framework version 4.5.1 but the dll which were referenced were compiled with the version 4.6.1.
So have updated the my project version. I hope it works for you.
This is the problem:
C:\Users\Noob\csharp>csc test.cs
You haven't added a reference to the DLL. You need something like:
C:\Users\Noob\csharp>csc test.cs /r:SnarlNetwork.dll
(or whatever the assembly is called).
Alternatively, if you haven't got it as a separate library, just compile both files:
C:\Users\Noob\csharp>csc test.cs SnarlNetwork.cs
If you haven't compiled an assembly but want to, you can use:
csc /target:library /out:SnarlNetwork.dll SnarlNetwork.cs
csc Test.cs /r:SnarlNetwork.dll
(In fact, specifying the output file is unnecessary in this particular case, but it's still clearer...)
Edit: Oh ignore me, you're not using Visual Studio.
Have you added the reference to your project?
As in this sort of thing:
It might be due to "client profile" of the .NET Framework.
Try to use the "full version" of .NET.
This usually happens to me when I have a using statement but have forgotten to reference the assembly that defines the namespace.
But in your case, as the namespace is defined in a file in your project, you have forgotten to tell the compiler about the snarlnetwork.cs file.
See csc compiler examples
I had this error on a MVC Project. And after a long research i found out that the .cs file containing some of the classes i referenced in the main project had a Build Actions set to "Content" ...
After changing it "Content"->"Compile" the error disappeared.
most of the problems cause by .NET Framework. So just go to project properties and change .Net version same as your reference dll.
Done!!!
Hope it's help :)
I resolved this by making sure my project shared the same .Net Framework version as the projects/libraries it depended on.
It turned out the libraries (projects within the solution) used .Net 4.6.1 and my project was using 4.5.2
i also faced same problem,
Reason: why i faced this error is,
rather then creating new partial view,
i have created class and then renamed its extension from ".cs" to ".cshtml".
Solution:
Just delete that rename view and re-create proper partial/full view. it will work fine after that.
Check your Web.Config and find namespace = . you can remove or if you need it you must create new
I had the same error when used cs file was located inside project folder, but did not referenced from .csproj of parent project.
Intellisence see this file inside project folder, but compiler does not see it because of missing reference in .csproj
I have resolved this problem by adding the reference to System.Web.
I also got this error due to a missing reference.
The reason I did not notice is because Resharper offers to add a using and a reference. Adding the using succeeds (but it's highlighted grey), syntax highlighting of missing classes works (sometimes), but adding the reference fails silently.
When manually adding the reference an error pops up, explaining why adding the reference fails (circular reference). Resharper did not pass this error on to the GUI.
I had the same issue when I clone my project from Git and directly build the solution first time. Instead of that go to the local repository in file explorer and double click the solution file (.sln) solved my issue.
I had a similar problem after first pulling and starting a new solution. It was fixed in visual studio by first cleaning the project. Then restoring the packages. When I built again, there were no more type or namespace errors.
Theoretically, if the the client framework is higher than the library framework client project builds successfully. So I suggest you check the Platform Target to make sure there is no conflicts.
right mouse button project > Properties > Build and uncheck Prefer 32-bit which is available for console project only. And check both projects target the same platform.
[
In my case, just "add refence" and browser the DLL file. it works for me.
I had this issue when I first cloned my project from Git to Visual Studio. I just had to update my NuGet packages, and then I was good to go!
Project > Manage NuGet Packages... >
Then update the packages. It notified me and there was a yellow bar with a button that I pushed and it downloaded the packages!

Categories