I'm using an application that uses Visual Studio and C# for it's built-in scripting. I want to use NUnit for testing but the environment doesn't understand nuget packages or add-on dll's so it discards anything that isn't source code each time it saves and reloads a project.
I was hoping that I might be able to get around this by including the full NUnit source code in a folder in the C# project and perhaps using something like the lite-runner to run the tests.
Any advise on how to achieve this?
I converted one of our commonly used libraries to .NET standard 2.0 for mobile application use as well as use in existing applications.
Using this library in an existing Mvc application (4.7.1 Framework) it builds and runs successfully but the Visual Studio IDE reports a list of build errors for the controller classes around not being able to find elements of the library. The using clause of this library is also greyed out in the controller classes.
Is there an easy way to resolve this?
Upgrading from MVC 5.2.3 to 5.2.6 has solved.
First of all, I don't know much about Roslyn. I went through a few tutorials hot to generate code and how to parse a string containing code.
So far, everything is clear to me.
Here is my question:
I'm using dotnet core 1.0.1 on Linux.
I created a new project with some interfaces defining some properties.
What I want to do is to create a program in which I can load the project, run trough the interfaces (*.cs files) and generate some code.
My problem is, I don't know how to load/open a c# project with Roslyn.
The tutorials I found are using a windows environment. These samples doesn't work on my environment because there are some dependencies to MSBuild or Visual Studio. I read and tried some things about the AdhocWorkspace, but I didn't manage to open an existing solution this way.
Can anyone give me a hint how to start?
Is it possible to open/load a project (*.csproj) and run through all *.cs-files?
Thanks in advance.
Currently, there is no good way to open .Net projects using Roslyn on .Net Core.
See this issue on the Roslyn repo, where the recommended solution is to use code from the Omnisharp project.
I need to create a setup project for my application. I need to add launch condition to make sure user has .Net framework 3.5 or higher installed on his machine. Is there a way to do so?
I have tried creating the setup project in VS 2005, 2008 and 2010. I have also tried setting up the version in launch condition to be 3.5 and then opened the project file in notepad to set "Allow Later Versions" to true, without any success.
The setup still asks me to download .Net framework 3.5 when I have .Net framework 4.0 installed on my system.
Any help will be deeply appreciated.
Thanks,
Manjeet
I think you don't want to edit project file manually. "Allow Later versions" flag is for your application not for .net framework I think; isn't it?
If you do as per this tutorial it should work fine. I've never seen your problem before. I think you must have done something wrong, other wise it should work fine.
I was also experiencing the same problem. I found that
- Visual studio 2008 started to use ToolsVersion attribute to target the framework
- Framework 4.0 doesn't include framework 3.5
In my case, I installed 3.5 (along with 4.0) and the setup is working fine now.
I can't seem to get my application up and running on my dev server and I'm not sure why.
I have compiled my code in VS 2008 with a target framework of 3.5. I am using 3.5 mainly because I have implemented LINQ rather extensively. Compiling and runs local without any problems.
The hang up is that my server only has the 2.0 .Net framework and upgrading to 3.5 is apparently not going to happen.
I was under the impression after doing some research that as long as I was trying to execute compiled code the server would not need 3.5 installed.
Today I am trying to publish to the server and I can't get past this error in my WEB.CONFIG
Configuration Error
Parser Error Message: Child nodes not allowed.
providerOption name="CompilerVersion" value="v3.5"/
EDIT ADD ON QUESTION:
I have seen some posts about possibly setting my references to "copy local" which might allow me to run on the 2.0 server. Thoughts?
You are right in that 3.5 runs on the 2.0 CLR, but 3.5 contains libraries and if you have used any of those, you're out of luck unless you install 3.5 on that server.
There are plenty of options for a 3.5 program to not run correctly on only 2.0, so I'd consider downgrading the program, or upgrading the server.
Note regarding copy local. Even if you copy all the 3.5 libraries that your app uses, there is no guarantee it'll work and most likely it won't. Even so, distributing the libraries with your app is expressively prohibited by the .NET license.
Since you have stated you use LINQ, the only legal way to get your app running is to install the 3.5 license.
Or, you can rewrite your app using only 2.0.
I'm pretty sure that LINQ is one of the things that makes 3.5 a requirement. A lot of the other things, like lambda expressions etc. are just compiler trickery.
Because System.Linq is a 3.5 feature, the framework is required to be that version.
A good way to determine would be to change the target framework to 2.0 and see if it builds.
Code compiled against 3.0 or 3.5 may run on the 2.0 framework, but only if you do not use any libraries that are specific to the 3.0+ framework. One good way to find what's causing your code to fail is to switch your target to 2.0 and change things so that it compiles. Since one of your target installations is .NET 2.0, you are going to have to write .NET 2.0 code; this is not unique to .NET. In the past, writing an application that executed in both Win95 and WinNT involved extra work for the developer to carefully make sure the appropriate API was used.
Technically, 3.5-targetted code can run on 2.0 with no problems, but there's some gotchas you have to watch for. If anything accesses something that is unavailable in .NET 2.0, that will fail. This doesn't happen when the application starts, it happens when the application tries to make the call. I tested this by making a console application that does a little bit of output, then tries to display a WPF window. The output is made, but the application throws an exception when it tries to display the window on a machine with nothing but .NET 2.0.
Another gotcha is that VS 2008 actually comes with the .NET Framework 2.0 SP1, and there are a few types and methods in SP1 that are not in the normal 2.0 Framework. Visual Studio will not flag these methods as unsafe.
Finally, if this is a web application, the default web.config file for 3.5-targeted projects is very different than the web.config file for 2.0-targeted projects. Make sure you're distributing a compatible web.config. This is likely the problem you are encountering. A cheap workaround might be to change your target to .NET 2.0, copy that web.config, and use it in this case. Keep in mind that if you are using any 3.0+-specific language features or types your code will still fail, but this should get you past the web.config.
You're not going to be able to run code targetted to 3.5 on the server unless you get 3.5 installed on it.
The problem isn't your code, rather that the required libraries will be missing.
This is not possible. Although the CLR has not changed (like it did between v1.1 and v2.0) The libraries have. You cannot run a 3.5 app that doesn't have the 3.5 fraework installed. All of the Linq features are made possible by the 3.5 framework.
One error is in Web.Config. The published Web.Config is setup to allow compilation from .NET 3.5, which is the reason it includes build provider information.
Beyond that, your code won't run. By using LINQ, you're referencing assemblies that don't exist in .NET 2.0.
I was just going to leave a comment by my rep is not quite there. I agree with the crowd so far and believe that lassevk's answer is the best so please give him the rep for that. One this I wanted you to know about though is that once you install 3.5 on your IIS server (6 or better). When you go to the IIS Manager and right click on your website to access the ASP.Net tab. You will see AFTER the install of the 3.5 Framework that there is no 3.5 option available. It will still show it as 2.0.50727. Don't worry about that, it will still work just fine. Because of this inconsistence (thanks Microsoft) some confusion has been caused. Actually I think this is why you may have thought that 2.0 would run your 3.5 code just fine. Hope this helps and anyone please edit this so it makes more sense.
You can may use of some C# 3 features whilst targeting .NET 2.0. Its the language features which by the time its compilied to IL will run on the 2.0 CLR regardless of whether that CLR is part of a 2.0 or higher framework install.
Hence you can use anonymous types, extension methods and Lambda expressions but as soon as you do things like LINQ you then need external libraries that are part of 3.5
If you are only doing LINQ to Object you could add the LINQBridge to your distribution.
Another problem you can run into is if you are shipping a web application that includes the source code, such as code behind files, in line code and .cs in the App_Code folder.
You can end up shipping C# source code which compiles on the developement machine with C# 3 compilier present but fails to compile on a server only equiped with C# 2. In this case you can't use any new language features either.
What's worse is that specifing the .NET 2.0 framework as the target in the Visual Studio doesn't stop you using C# 3 language features. You get no warnings that such syntax will not compile on a 2.0 machine.
Hence if you are shipping such a web app, you'll need to compile pretty much everything first.
You can just copy over the 3.5 dlls onto the server. You can absolutely run 3.5 code on a 2.0 server.