How do I reference a UWP+NET46 portable library from a .NET 4.6 console application? - nuget

I have a portable class library project that targets .NET 4.6 and Universal Windows Platform. This class library contains just one class with the following line of code in its constructor:
Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
Now I create a new .NET 4.6 console application project in the same solution and add a project reference to the portable class library. Calling the method that houses the above line of code results in the following exception at runtime:
Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
What am I doing wrong here? There are no compile-time errors or warnings.
Things I have tried: add missing(?) NuGet package manually
It seems that System.IO.FileSystem is a library delivered via NuGet, as part of the Microsoft.NETCore mega-package. Okay, perhaps I need to explicitly add this package to any project that uses my portable class library. I attempt to do so.
Could not install package 'Microsoft.NETCore.Platforms 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
No luck with this approach.
Things I have tried: create a project.json file
While there is no clear info on the web, I read a few tidbits about a new project.json based NuGet harness or build system. Just to experiment, I created the following project.json file in my console application project:
{
"dependencies": {
},
"frameworks": {
"net46": { }
},
"runtimes": {
"win-anycpu": { }
}
}
It works! The runtime error goes away! However, I soon found that this was either not the right solution or not a complete solution. I started writing some code to read configuration section values, which involved making use of the IConfigurationSectionHandler interface, and got the following compile-time error:
error CS0246: The type or namespace name 'IConfigurationSectionHandler' could not be found (are you missing a using directive or an assembly reference?)
This interface is part of the System assembly. I see a reference to this assembly, but it has a yellow exclamation mark icon, and a warning appears in the warnings window:
The referenced component 'System' could not be found.
This is where I ran out of ideas. Am I missing something totally obvious?

I have found the solution. My initial attempt was to install the Microsoft.NETCore package into the console application, resulting in the error shown in my original post.
However, if I install only the narrowly-scoped packages, e.g. System.IO.FileSystem, then I achieve success and the application works correctly. Apparently there is something special about the Microsoft.NETCore "master package" that prevents it from correctly installing into dependent projects.

Related

I don't know how to call using UnityEngine.XR.ARFoundation in a C# script inside my own Package in Unity

I don't know how to call using UnityEngine.XR.ARFoundation in a C# script inside my own Package in Unity.
I have added ARFoundation in Dependencies of Package as shown in the image. But I'm getting "error CS0246: The type or namespace name '~' could not be found (are you missing a using directive or an assembly reference?)". How can I resolve this?
I solved the problem by creating Assembly Difinition Files in my own package and adding references to Assembly Difinition References.
I fixed this issue in "Edit" ... "Preferences" ... "External Tools", by checking "Regenerate Project Files"; this hopefully regenerates all the necessary ".csproj" files for IntelliSense tracking.

Trying to install package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references

I used NuGet Package Explorer (for the first time) to create a .nupkg to share with others. I have one DLL that targets NetStandardLibrary 2.0,
But when I try to add the package I receive the following error:
Could not install package 'iCANMVCSDK 1.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.7.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
I thought that by using NETStandard 2.0 it could be installed in any .NET app. I also tried adding additional assemblies:
I rebuild, repackage, and I still get the same error. What am I missing?
I tried editing the project file like this:
<TargetFrameworks>netstandard2.0;net472</TargetFrameworks>
When I try to build after adding net472, I receive the following error:
The type or namespace name 'Http' does not exist in the namespace 'System.Net'
What really makes no sense to me is that I can add the DLL directly into the project (the one that targes NET 4.72) and it works as expected. The problem is when attempting to install it as a NuGet package.

Error saying "Module Not Found" when adding SPM which uses other SPMs as dependencies within itself

I have been creating a Swift Package Manager. It uses 2 other SPMs within itself. SPM compiles fine when compiled independently. As soon as the project is imported into an Xcode project I get a compiler error saying that:
No such module 'ModuleName'
Note: The ModuleName in the above error corresponds to the package imported within the package that is being imported to my project.
I have been stuck on this for a pretty while now and have tried the following:
Removed and readded the SPMs to dependencies to my SPM, and then tried importing my SPM to my project (I did this before and after each of the other steps too).
Checked to see where these packages where being added as dependencies. It shows up in the SPM main target Module -> Build Phases -> Link binary with libraries. I additionally added it to the Dependencies section to see if it changes anything.
Tried adding SPMs to ModulePackageDescription target to Dependencies section.
Added the dependencies in the Package.swift file as follows.
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "package1_url", .branch("master")),
.package(url: "package2_url", .branch("master"))
]
Adding this would import the other dependencies to my Xcode project. I don't exactly want this to happen because in case I try to use another version of the SPM that is being imported within my SPM, it would cause conflict between the two versions. But I'm willing to do this if it's the right way to go. But even adding dependencies in Package.swift didn't work for me. How would I resolve this issue? Let me know if anyone has faced the same issue.
Are the libraries public classes also need to contain constructors?
public struct NumbersA {
public init () {
}
}
also add them to the dependency Package.swft->dependencies: ["NumbersA"]),

Trouble with Importing Java Libraries into a project with NetBeans

I am having some issues with importing library which is needed to complete an assignment that I have been set.
I'm not sure if I have added the library to the project, but the classes from the library appear to be in the libraries section of the project.
http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ
I added the libraries by right clicking on project1 and going to properties:
http://imgur.com/Co6IOzq,qCJaXHh,ZJVUnbZ#1
However whenever I have "package project1" at the top of Project1.java I receive a message that MaInput - which is one of the classes in this library - is not recognised:
cannot find symbol:
symbol: class MaInput
Whenever I take away "package project1" when trying to compile it reads:
Error: Could not find or load main class project1.Project1
Java Result: 1.
The problem is that you are trying to access a class from default package from a named package and this is not allowed by the Java Specification.
So, in this case, create your assignment in the default package as well.

Flex compiler error: "please put definition in a package" for classes that ARE in a package

This is with Flexbuilder 3.2, Eclipse 3.3.2.
I am moving my development environment to a new machine. Actionscript classes that compiled in the old environment now get a compile error:
A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be externally visible, please put the definition in a package.
I do declare the package in these classes - I think failure to declare the package is the usual reason for this error.
To add to the mystery, many classes in this project compile without errors.
What should I check to diagnose this?
Problem solved - I had missed out some items in the path in the environment where I was launching Eclipse.
"C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0"\bin
"C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0"\frameworks
"C:\Program Files\Adobe\Flex Builder 3 Plug-in\jre"\bin
"C:\Program Files\Adobe\Flex Builder 3 Plug-in\jre"\lib
I'm amazed anything at all worked with this much missing from my path.