.net framework (WPF) dependencies of references - c#

I have a .NET framework WPF project that references a .net standard library that I wrote. This library references io.ports.dll
I found that there is a problem with .net framework referencing .net standard projects and that it would not copy the io.ports.dll to the output folder. The solution here was to add the dependency to my WPF project also which solved the problem.
However I noticed that the two projects reference the io.ports.dll from different locations.
The WPF project references from
project location\packages\System.IO.Ports.4.5.0\lib\net461\System.IO.Ports.dll
The .net standard library io.ports.dll location is
C:\users\.nuget\packages\system.io.ports\4.5.0
The DLLs have different sizes, although they are the same version.
The problem appears when I use advanced installer to create a .msi.
It gets very confused and tries to copy both DLLs and in the end my .net standard library tries to read the wrong DLL.
Anyone have any idea how to solve this?

Pavel answered (now deleted) that it was due to my GUI project using the old packages.json. This solved the original problem. Another problem was that the io.ports dll has a dependency on Microsoft.Win32.Registry.dll which I also had to add to the GUI project.

Related

producing all included exe for c# .net 4.7.2 project

I have a class library project that is referencing .Net Framework 4.7.2 . I need to create an exe which will contain all the references of the project. I will not have access to any code or project references on the VM, where this exe needs to be run. Everything should be included in this one exe.
I have come across this question on SO.
Are solutions such as costura.Fody and ILMerge mentioned in that question addresses the same issue that I have?
( I am new to .Net and C#) and I was in doubt because I am not sure of managed assemblies vs. any other as mentioned in one of the answer in question that I referenced
Can someone help in clearing this or suggesting any other solution, if there is any.
Costura.fody worked pretty much out of the box for .net 4.7.2 framework. When executable was compiled it included everything. One way to know is that the size of your executable will increase . The other way is to use tool like ILSpy to look inside executable

Not able to use My Class library in C#

I am using Visual Studio 2017. I have a solution and in that solution I have 2 projects. One project is a library I made. This library is using Target Framework .Net Standard 1.6 and Output type: Class Library. The other project is a Windows Application using Target Framework: .Net Framework 4.6.1 and output type: Windows Application.
I added my class library to my windows application and the reference is in the Reference section, but when I try to use a class from the library, it cannot find it. Also I tried adding the "Using MyLibrary" and it still cannot find the reference. What else can I do?
I'm not sure why but the whole solution must had been corrupted or something. So I remade a whole new solution and created the projects again and copied all my files over and it worked. Not sure what the whole problem was but it is now working.

How to use wixlibs as file references with support for different platforms?

I just am trying to replicate my distributed C# project structure to WIX setup projects. Now there is the following problem:
LIB: a C# library solution that builds AnyCPU .NET dlls from several C# projects
APP: the dlls from LIB are referenced (as file references) by this main application solution. Additionally there are platform dependent libs included in this application solution, therefore it is important to being able to create setups for the two specific target platforms x86 and x64.
Now I started to create a wixsetup project within the APP solution (which works fine). Then I proceeded with creating a wixlib within the LIB solution that references the LIB .NET dlls into the wixlib.
Now the problem:
The wixlib references the AnyCPU .NET dlls within a DirectoryRef which seems to be platform specificly tagged when creating the wixlib. Therefore I have to go back to the LIB solution, build the project with one platform target, copy the built files (via SVN externals mechanisms) to the APP solution, build this project with the exact same target platform as the wixlib was created with and repeat this procedure for creating the other platform.
It may seem that this is kind of complicated, but doable. Due to the fact that I omitted several other library solutions for which the same problem applies and the fact that all those libraries are used in multiple application solutions and - finally - everything has to run on our build server automatically as well, it is clear that this will not work.
I know of the following solution, though:
Double the .NET dll references within wixlib to assign them to different DirectoryRef INSTALLDIR and INSTALLDIR32 e. g. and to implement those different directory references in the wixsetup.
But this would complicate things as well and is not my preferred solution therefore - if there is an alternative.
If there is no smart alternative, just tell me and I will do things as described in the last paragraph.

easiest way to convert .NET project from 4.5 to 4.0?

I have a .NET application that I built in 4.5, which has references to a bunch of libraries that were built in 4.5, which themselves have references to 4.5, etc. A user group that I'm trying to distribute the application to is having problems running the executable because they have 4.0 installed; in particular, they're getting a MissingMethodException:
Method not found: 'System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)'.
Because we may have trouble getting each user upgraded to 4.5 (as none of them have admin permissions on their machines and this would require a separate upgrade request for each user), I'm looking at finding an easy way to rebuild the project as 4.0. This seems to require that I rebuild every library and its referenced libraries in 4.0; is there an easier way to do this than going through each library one by one and building a 4.0 version? I'm thinking maybe like a one-click option for "Rebuild all referenced libraries in target framework" or something like that.
If you have dependencies on .Net 4.5 DLLs then you will need to also get .Net 4.0 versions of those if you want to successfully downgrade your project. A .Net project can only reference .Net DLLs up to the same version of .Net as the referencing assembly.
The easiest way to do this is to use something like NuGet to manage your dependencies. Note that when you change the target framework version of your project in VS you will need to uninstall and re-install dependencies with NuGet as NuGet does not automatically do this for you when you change the target framework version.
Of course if all the dependencies are to your own code and you aren't publishing this through a dependency management system like NuGet you will need to downgrade all your other code to .Net 4.0 as well
When I use Visual Studio, I right click on the project, change the framework, fix the References and recompile. Usually straight forward.
Please, have a look at this MSDN page to correctly switch your project to a lower target framework without problems! It is a little bit outdated for what concerns versions, but the process is the same described!
This is based on my experience. I had an application initially created in .net framework 4.5 but I wanted to convert it in .net framework 4.0. I created new project initially created 4.0 and then I did copy and paste of all the forms and controls of my previous application and it works. Framework 4.5 is using Aero2 and 4.0 is Aero... Good Luck :)

Visual Studio 2012 How to debug "Unable to add reference to project x" error?

In Visual Studio 2012 in a blank new Class Library I am trying to add reference to an existing project in the solution, also a Class Library, MonoGame.Framework.Windows8 (https://github.com/mono/MonoGame), but get the error:
Unable to add reference to Project MonoGame.Framework.Windows8
I have built the existing library, MonoGame, successfully and made it a dependency of the new one. What could be the problem?
(It's extremely annoying the error message does not give a reason!)
Trying to add the built dll has a reference gave a more explicit error message which has solved the problem for me, it said:
“A reference to ‘x’ could not be added. The project targets ‘.NetFramework’ while the file reference targets ‘.NetCore’. This is not a supported scenario”
The MonoGame Class Library is a Class Library (Windows Store apps) type! (The bit in parenthesis is important! Presumably the difference is the Windows Store apps type use .Net Core which is not the same as .Net Framework).
So to get it working your project must be a Class Library (Windows Store apps) which is available under the Windows Store option in Add New Project.
I suspect the problem is to do with the 'Target Framework' in project options.
I don't know how MonoGame works for Windows 8 but when you're developing for Android the target framework options are the different versions of Android [e.g. Android 2.2 (Froyo)]. When you create a regular class library you have choices between the different versions of the .NET framework or Mono [e.g. Mono / .NET 4.0].
Unfortunately, these frameworks are not compatible with each other. You can't add a project reference for Android to a .NET framework class library and visa-versa.
The solution is to use a Portable Class Library. They are specifically designed to deal with this issue. The downside is that you will only have access to the subset of assemblies provided in the lowest denominator you choose to target.
You might also want to consider code sharing between projects using linked files. It can make maintenance a little trickier but gives you a little more control over code that should compile in both target frameworks but doesn't fit into the portable class library. Here's a related question:
Project reference vs. file links in Mono multi-target projects
The key to all of this once you understand what's going on here is how you structure your solution. With a little care you can have nearly all your code shared across different platforms.
I might be because of both projects are using different Framework versions and change the Framework versions in both Projects of properties section then your problem might solve.
Same question I guess here:
Visual Studio 11 metro apps unable to add reference?
The answer was:
What are you adding a reference to? Metro style apps can only add references to other Metro style class libraries or portable class libraries

Categories