Can J# code run on JVM - j#

If I create a J# Application is there any way I can execute it on JVM as well

No, J# programs are designed to run on the .NET platform. See the J# FAQ.

Yes - sort of. If the Java you write will compile using javac then you can have one source base and compile for both J# and Java. We do that for our reporting engine. If you do this on .net 40, you need Calling J# code from .NET 4.0.
But you cannot run the J# binary on a JVM.

Related

NuGet package for C++/CLI library for use in C# libraries

What is the right way to construct a NuGet package for a mixed-mode C++/CLI library?
I have 32-bit and 64-bit builds of the dll, and an ASP.NET Core app (targeting full .NET framework only) using it that will be built for both platforms. The app's solution platform is "AnyCPU".
I have tried using the /runtimes/ folders, but then Visual Studio can't find the managed code to compile against.
Currently I have 2 packages, like "MyLibrary" and "MyLibrary64", with the dll in the /lib/ folder and conditional PackageReference in my csproj, but this doesn't feel right. Additionally, when I compile in VS, I get:
warning MSB3270: There was a mismatch between the processor architecture of the project
being built "MSIL" and the processor architecture of the reference "MyLibrary.dll", "x86".
This mismatch may cause runtime failures. Please consider changing the targeted processor
architecture of your project through the Configuration Manager so as to align the
processor architectures between your project and references, or take a dependency on
references with a processor architecture that matches the targeted processor architecture
of your project.
This questions is similar, but has no answers:
Create NuGet package for C++/CLI (mixed) assembly
Update/Clarification:
the app can run either hosted in IIS (64-bit) or as a standalone self-hosted installed application (32-bit), so both are unfortunately necessary.
As Hans already pointed out, the platform of the C++/CLI project must match the mode in which the managed code runs. Hence, an assembly set to AnyCPU that references a (mixed-mode) assembly set to x86 may always fail to load if it is loaded in a 64 bit process.
There are three ways I know of to fix this issue:
First, live with the warning and make sure that the process in which the assemblies are loaded is always a 32-bit process. I wouldn't recommend this.
Second, switch your application to x86 which guarantees that it always runs in a 32-bit process. This is the easiest and cleanest way, but it pins you to 32 bit.
Third, make a NuGet package that contains both, 32- and 64-bit builds of your mixed assembly together with an automatic loader switch. To this end, you need to make sure that the mixed assembly is not found (i.e. by renaming it in the NuGet package) and that there is a AnyCPU assembly that registers AppDomain.AssemblyResolve with an event handler that loads the 32- or 64-bit version of your mixed assembly, depending on the current process.
The third approach allows to provide a NuGet package with mixed-mode assemblies that can be referenced from AnyCPU assemblies. Note, however, that AppDomain.AssemblyResolve is a global concept and may interfere with other components in your application, which may lead to non-trivial bugs.

NUnit-console wants me to install .NET 3.5

I'm trying to run some NUnit tests written in Visual Studio on the command line using NUnit console. The tests are built using .NET 4.5.
To run them, I'm typing:
nunit3-console mytests.dll
And I keep getting a pop-up which tells me "an application on your PC needs the following Windows feature: .NET Framework 3.5 (includes .NET 2.0 and 3.0).
I've tried forcing NUnit to use 4.5 by saying
nunit3-console /framework:net-4.5 mytests.dll
But I get the same thing.
I tried installing .NET 3.5, but it can't be installed (I guess because I don't need it as I already have 4.5).
The tests run fine when run from Visual Studio using ReSharper or in the NUnit GUI...
I've created a really simple solution (tried with .NET 4 and .NET 4.5) which has a NuGet reference to NUnit 2.6.4 and one class (below):
[TestFixture]
public class Class1
{
[Test]
public void MyTest()
{
Assert.Pass();
}
}
I still get the same error.
How can I fix this?
That executable itself (nunit3-console) must have been produced by C# compiler to target .NET Framework 2.x/3.x (for the so called compatibility). Thus, when it runs on a pure .NET Framework 4.x Windows, you see the other compatibility feature by Microsoft, where it always prompts and asks to install .NET Framework 3.x (you must do that via Programs | Add/Remove Windows feature). Both of them are ridiculous as people should rarely use .NET Framework 2.x/3.x (though Microsoft will keep supporting .NET Framework 3.x as part of Windows).
To get rid of that prompt, you can enable .NET Framework 3.5 (which also gives you the bits to compile against .NET Framework 2.x/3.x). Or you modify its nunit3-console.exe.config file to use <supportedRuntime> to force .NET 4.x is used to load this executable.
I guess the NuGet version contains a proper .exe.config, while the MSI version not. You can analyze further for sure.

Best strategy to target .NET 4 from a NuGet package with a portable class library

I have a NuGet package for a library that is currently implemented only for .NET 4. But I have ported library code to support various platforms (WinRT, SL5, WP8) so ideally I would like to package it as a portable class library (PCL) to simplify the maintenance. But the library is using LINQ to XML (XELements etc.) that requires targeting .NET 4.0.3 and installting .NET 4.0.3 on a client machine.
So I have a dilemma regarding how to target plain .NET 4. If it was not about NuGet packages and I had a control of the user base I could simply state as a prerequisite installing .NET 4.0.3 runtime. However, I don't want to limit the user base in any way, so it looks like I will have to have two versions of the library: portable that targets .NET 4.5, SL5 and WP8 and non-portable targeting just .NET4. What's silly is that both libraries will have exactly the same code since LINQ to XML is of course supported in .NET 4, it's just PCLs that don't have such support when targeting .NET 4.
My first question is whether this seems to be a right strategy? The alternative would be to take away all XElement-dependent code from PCL and have it in non-portable parts, but this does not seem right because the code will be exactly the same for all libraries.
The second question is whether it makes sense to target .NET 4.0.3 from a PCL at all: if I have separate version targeting .NET 4 will users that have .NET 4.0.3 runtime installed gain anything from getting a PCL rather than plain .NET 4 version? I know .NET 4.0.3 has other improvements but those don't affect my library.
Yes, I think the best thing is to create two versions of your library, one targeting .NET 4 and another portable library that targets the other platforms you support. Use source file linking so you don't have to have two different copies of your source code, just two different Visual Studio projects.
You only need one NuGet package though. Put the .NET 4 version in lib/net40 and the portable version in lib/portable-net403+win8+wp8+sl5 (or whatever combination of platforms you decide to support). Then NuGet will install the right one depending on what a project is targeting. NuGet 2.1 or higher is required for this to work for the portable version.
In reference to the question about .NET 4.0.3, it's about giving the consumers of your library flexibility. The people using your library are using it to create applications. Supporting .NET 4 may not be as important to them as it is to you. By supporting .NET 4.0.3 in the portable version of your library, it means that if they choose to require .NET 4.0.3 in their apps, then they will be able to use your library from their own portable libraries and more easily share their app code across platforms.

How to build software that doesn't require a framework on the user's machine?

I am an ASP.NET developer, but now I want to build a software that can be installed on my PC. Software built in .NET platform only works when the .NET Framework is installed, and software written in Java only works if the JDK is installed. When I install programs like Firefox, uTorrent, etc., I don't need to have any frameworks (.NET, JDK, etc.) installed. How do I write software that doesn't depend on a framework?
You will have to use a language that isn't dependent on a framework or otherwise only target clients that are already have your framework installed.
If you chose C or C++ for example, you would distribute binaries to your client that contained machine code. This code would not be dependent on a runtime environment (like C# or Java) or an interpreter (like Python or Ruby). This is the way that applications like Firefox and uTorrent are written.
"When I install programs like Firefox, uTorrent, etc., I don't need to have any frameworks."
Actually, you do. They just tend to use the C++ frameworks, such as MFC, some of which are already installed. Even then, there are installers for these frameworks that are included with other application installers (usually called Microsoft Visual C++ 2008 SP1 Redistributable Package or something like that. See Also: Visual C++ Deployment).
Now, having said that, they don't require a virtual machine (like a JVM for Java or a CLR for .NET), because C++ compiles down to x86 / x86-64 machine language to be executed directly by the operating system.
Fundamentally you always have a "platform", which is the operating system. Traditionally if you want to write code that will run on multiple operating systems you would use a fairly portable language such as C++ that produces native executables for a target operating system. Still, there are differences between how different operating systems work. There will therefore be parts of the C++ (or other portable language) code that are specific to that OS. You try to isolate those parts as much as possible to minimize the effort to port between OSes. Still, that effort is typically very substantial. You are also limited to the least common denominator of features available on all target operating systems (unless you create a custom version for a given OS that exposes its special features).
This is complex, time consuming and expensive. That's the reason technologies such as Java and .NET were created.
If You want to build really platform independent software You will finally end up with solution like Java Runtime or .NET. What You could do, You could thing about writing application in such way that You are able to compile/run it on most known platform, and of course then You need middleware to translate Your application's objects into platform objects (functions, whatever...).
I have seen solutions made in Pascal for DOS in such layer of abstraction that with little effort it was moved directly to Delphi for Windows without touching application logic.

Cross platform project automation

The web shop where I work we do both .Net and PHP/Linux development. We'd like to start automating a lot more of our deployment processes using a common system that can be used for both. What would you recommend as a good common scripting language or automation system (like Ant or Maven) that works well for both .Net and Linux development?
I have no experience with Maven, but we've managed to get Ant to do everything we've wanted on multiple platforms, just by virtue of the fact that you can extend it with any Java program to do special tasks not included with the Ant application itself.
And then Java can, if necessary, call any external program you want to by using Runtime.exec(). Loses a bit of the portability but it was required for some command-line tools under both Linux and Windows.
You may want to see how Perl does cross platform automation. The design for Perl6, seems to be a bit better designed, but the Perl5 design has had many years to develop.
Perl has been ported to many different platforms, not just Linux and Windows.
You may get some mileage out of Capistrano. It is rails centric but it is pretty general purpose, and I believe it has been extended to do other things also. Not sure how well it plays with Windows and .NET, but worth a look.
You can develop .net on linux using Mono.
On that linux server you can use both .net and php.