Having just installed VS2015 Update 1, I discovered the C# Interactive window.
According to the second post in that series, you should be able to import a project from your solution.
When you want to fire up the C# Interactive Window you can just right click your solution and select "Reset Interactive from Project"
However, this option is not available on my project. I'm using a Console Application to test, and have pushed the framework up to 4.6.1 from 4.5. However, this has not worked.
Additionally, I have attempted to manually import the project. Looking at the screenshots on the website, I should be able to do this like this: #r "ConsoleApplication7.exe" but when I do, I get the following exception:
(1,1): error CS0006: Metadata file 'ConsoleApplication7.exe' could not be found
It will pull in via the filepath, e.g:
#r "bin\Debug\ConsoleApplication7.exe"
However, this is a little unwieldly. Especially since whenever you make changes to the classes, it requires a #reset and re-import.
Is there a better way to import Projects into the Immediate instance?
According to the Comment from Jason Malinowski
It doesn't really answer your question, but unfortunately we had to cut the "Reset from Project" command in Visual Studio 2015 Update 1 just because we were crunched getting everything else done. We don't like that it's not there either.
Jason Malinowski
Therefore, at this time (2016-02-04), the "Reset from Project" option is not available.
Projects can be imported manually, by using the following command:
#r "bin\Debug\ConsoleApplication7.exe"
This should work when you are running the REPL with the solution open in the same instance, and when you have only one project.
At other times, you will need to use the full file path
#r "C:\MySolution\ConsoleApplication7\bin\Debug\ConsoleApplication7.exe"
Related
I have the following selective problem with VS 2019 and IntelliSense.
When I start typing a class name which's namespace is not imported yet, IntelliSense suggests it in the Autocomplete column.
Once I press tab instead of completing the name and importing the using directives it autocompletes the whole path e.g.:
Typing 'UserView...' -> App.Web.Areas.Users.ViewModels.UserViewModel
instead of importing -> using App.Web.Areas.Users.ViewModels; and completing the typing to just UserViewModel
But if I write the whole class name and then press Ctrl + ., then IntelliSense imports the using directive.
Do someone know which setting triggers this behaviour?
Actually, I did not face the same issue on my PC.
My Visual Studio 2019 version is 16.7.5 without any other third party vs extensions and I used Newtonsoft.Json.dll.
Actually, you should enable the option Show items from unimported namespaces and it will import using Newtonsoft.Json; automatically when you use TAB to complete the code.
In my side, I typed json and then use TAB to complete the class JsonArrayAttribute. And I did not face the issue as you described.
So I am confused that why this happened in your side.
Or you could try the following steps:
1) If your VS2019 is not the latest version, please update it to the latest version and the new version will add the latest, most comprehensive features.
2) disable any third party vs installed extensions under Extensions-->Manage Extensions in case you have installed some extensions which caused that.
3) reset vs settings under Tools-->Import and Export Settings-->Reset all settings
4) after that, close VS, delete .vs hidden folder under your solution folder, bin and obj folder. Then, restart your project to test again.
Besides, if I misunderstood your issue, please point out and provide any detailed info to describe the issue to help us troubleshoot it quickly.
How do I build sample code, split into folders in a repo, from a class or tutorial, in Visual Studio?
So - I'm pretty much a noob at C#, I've gone through a lot of tutorials and browsed through some large C# projects from work and built them, and done some other minor things. I'm going through a course on writing testable code on Pluralsight. He has a public Github repo for the code examples, writing-testable-code. I connected to the repo and downloaded it okay into a local Git repo. I was able to download all the packages from NuGet and they are all showing as the version he used (a few have updates, but I figured updating might break things).
I can't figure out how to run this code, build it, or run the tests in it.
What I tried so far
My issue is - I open the solution, and there are a bunch of files and folders - each module/chapter is split into folders (i.e. Module1/Easy, Module1/Hard, Module2/Easy, etc.). I want to build the Module1/Easy folder, including unit test examples, and run the tests.
When reviewing Module1/Easy, it has 3 files that should build okay - the program.cs has a main() and looks like a console app, the Calculator.cs has a simple class, and the CalculatorTests.cs has unit tests built for Nunit. The solution has NUnit, Castle.core, and things from later modules (Moq, AutoMoq, Unity, Ninject, etc.). It didn't seem to have a VS runner, so I added Nunit3TestAdapter - the guy in the course has resharper installed, which I don't, and he was using the Resharper test runner, which would explain why he didn't include it.
I tried setting the "Module1/Easy/Project.cs" file the "Set as Startup Item", since it has a main and looks setup as a console app. However, running it (the "Start" button turned into a "Program.cs" button), it fails saying it can't run a dll. The tests aren't showing up in the Test Explorer like some other small projects I've built from examples.
What's the right way to do this?
I'm not sure where to go from here. On the Build menu is only a "Build Solution" and one about Code Analysis - I'm used to a lot more options here. It feels like I have to turn this folder into a project, maybe? I can always reinstall the packages - but what is the best solution here?
I've run into this before on other book, tutorial, or class repos, but finally decided to figure out how to get this one working. I appreciate any help!
Notes
I'm running Visual Studio Community 2017 at the moment.
I can post some of the files, but the repo is publically available, and not sure exactly what to post to help.
Progress from comments and answers
Per Biker-Dude's answer, I switched the project to build a console app rather than a dll, and now I get a compile-time error for having multiple entry points (i.e. every module and sub folder has its own Main() function and should probably be a separate project).
After #1, I removed all folders but one from the solution, it will then compile, run the tests, etc. - but I eventually want to be able to at least separately compile every sub-folder - what's the best way?
The problem must be that the project must have the output type set to class libraries. Browse through the solution tree and:
Select your class's project> right click > Properties > Application >
Output Type > Console Application/ Windows Application.
This should fix it, if the other things are set up properly.
With the help of BikerDude's answer and stijn's comments, I was eventually able to play around with this and get some things working.
First of all, don't try to exclude any folders in this situation, that will just make things worse! They will still be in your underlying folder/repo, just won't be showing up in your solution anywhere, and you won't be able to create a new folder with the same name (weird decision...). And you'll have to add them back in as individual files - I think.
The best solution (so far)
The best solution seems to be:
Create a new project for each buildable set of files in the solution (in my case, at least one project per "module" folder). I used the ".Net framework console app" project type (right click on the solution, use Add/New Project) to get things to work, but this would depend on the particular course or tutorial repo you downloaded.
Move the folder or sub-folder that has the files you want to build out of the main solution and into the new project - you can click and drag to move it.
Visual Studio will make an empty, pre-formatted file in your project that you likely have to delete - for .Net apps, this is the "Program.cs" file in C#. For one of my folders this file already existed, and I had to delete the new one in order to build. Another folder from a different module was setup more like a library and couldn't build standalone, but this procedure did get me to being able to build the files and that allowed the unit tests to show up in the test explorer and run the tests successfully (which was the main point of that module).
Go to the solution and right-click and choose "Manage Nuget Packages for Solution". As long as all the packages are installed for the main solution, then they will all show up in the list of Installed Packages (you might need to click on the "Installed" tab). You can click on each package in turn, then on the right you can checkmark the new project, and the "Install" button should be available - click it. Repeat for all the packages to install them all. Note that you can cut out some repetition here if you create all the projects you need first, then you can install all of them at the same time in this step (i.e. checkmark all the new projects at once instead of reopening the package manager each time).
You might have to fix the NameSpace - it should be consistent within the files/folders you transferred from the original solution, but if you add any new files to play with things, the Namespace for it will likely not match, and to see classes, etc. in the original files, you'll have to update your Namespace on the new files.
Per BikerDude's answer - After transferring everything to new projects, if you keep anything in the original project that came with the solution, it might not be trying to build the right type of item. You may be able to fix that by right-clicking the project, selecting properties, and adjusting the "output type", but it may not have the options you need. If it doesn't, just create a new project with the right type and transfer the files as above.
After following the above steps, I was able to build each new project I created, using the original files from folders that I moved. Mainly I just needed to build, which enabled all the unit tests that this tutorial/class was focused on, but this allowed me to build the console apps as well, when present.
Thanks for the help from all in pointing me in the right direction!
I downloaded Roslyn code and built it successfully within VS2014 CTP 3. I am trying to run the samples that came with the source as part of Samples.sln solution. I can build Samples.sln successfully.
I try running ImplementNotifyPropertyChangedCS sample - I made the project the startup project within the solution and pressed "Start Debugging" menu item. As a result I am getting another VS2014 instance. I open a new project within that instance, create a property and try to refactor the property. I am not getting the option to Implement Notify Property Changed refactoring.
I checked the dependencies of the new instance of the visual studio - it does not depend on ImplementNotifyPropertyChangedCS.dll file. I looked at the output window of the first devenv instance - it seems like that ImplementNotifyPropertyChangedCS.dll was loaded but later was unloaded.
Please help.
I have been wrestling with the Android Calendar for a couple of days now and I'm at my wit's end.
Following the instructions found here:
http://docs.xamarin.com/guides/android/user_interface/calendar/
I have begun a new ICS project and added permissions to read and write to the calendar. According to the instructions linked above I should now be able to "interact with calendar data by using the CalendarContract class." However, when I input the first line of example code:
var calendarsUri =CalendarContract.Calendars.ContentUri;
I get an error saying that "The name 'CalendarContract' does not exist in the current context."
I have download sample code for the CalendarDemo located here:
http://docs.xamarin.com/samples/CalendarDemo/
I can open the project, manipulate the code, deploy it to my test device with the modifications that I have made and it works perfectly. The problem is that I cannot seem to get CalendarContract to "exist in my context" if I create a project from scratch. Even adding in the CalendarListActivity.cs into a new project won't work. This leads me to believe that there is something I have to set in Xamarin Studio, not via code and not indicated in their tutorial, that I have yet to find.
What setting or reference do I need to add into a new or existing project in order to use this feature? I've looked everywhere I can think of and cannot find the elusive switch, checkbox, reference or whatever is required. I've burned three days trying to figure this out and I have lost my patience.
I was able to reproduce the error you're having. I created an ICS project in Xamarin Studio and got the same message. I then loaded the solution in Visual Studio and noticed that the CalendarDemo project has a reference to Mono.Android v4.0, but the one created in Xamarin Studio only referenced Mono.Android v2.2 even though I specified Ice Cream Sandwich. That is why you're not able to build.
Changing the Target version in Project Options didn't seem to do anything. A workaround is to add
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
to the .csproj file. See the CalendarDemo project as an example.
BTW: This is on Xamarin Studio v4.2.2 (build 2). I don't normally use Xamarin Studio, so I have never had to deal with this. I'm not sure if it's a bug in XS, but it certainly isn't expected behavior.
Just as a test, I created another project in Xamarin Studio, but this time I just selected the standard Android Application project. Surprisingly, it referenced Mono.Android 4.3.0. So apparently there's a bug in the Android Ice Cream Sandwich project template.
I recommend using the standard Android Application project going forward.
If you are using Xamarin Studio, right-click on CalendarContact and select Resolve. It should give you two options, first will add "using Android.Provider;" to your using statements and the second will append the code to "Android.Provider.CalendarContract.Calendars.ContentUri"
...or just add manually the using statement. :)
You should import this library
> using Android.Provider;
> using Java.Util;
I am fairly new to C#..
I am using Visual Studio 12, the source I am using was last edited in VS 12.. But my problem is that it's throwing me this error:
First of all, my computer username isn't Martin, it is Administratoring - The creator of this project is Martin.. So that's where I guess it's coming from, but I don't know how to fix this.
I have tried editing in Project > Properties > Build > Output Path - And it still doesn't work. I am not too familiar with C#, and I've spent some time searching up for a solution but can't find it anywhere.. Probably because I don't know what I should be searching up (I've tried searching keywords and quotes from the error, but still nothing)
Try these:
Make sure that output path of project is correct (Project > Properties > Build > Output path)
Go in menu to Build > Configuration Manager, and check if your main/entry project has checked Build. If not, check it.
For those with this kind of problem - another solution:
Pay attention also to Warnings when you build solution. For example, I had referenced a dll built with higher version of .NET (4.5.2) than my main project (4.5)
After I referenced a dll built with 4.0 build process was successful.
Please try with the steps below:
Right click on the Visual Studio Project - Properties - Debug - (Start Action section) - select "Start project" radio button.
Right click on the Visual Studio Project - Properties - Debug - (Enable Debuggers section) - mark "Enable the Visual Studio hosting process"
Save changes Ctrl + Shift + S) and run the project again.
P.S. I experienced the same problem when I was playing with the options to redirect the console input / output to text file and have selected the option Properties - Debug - (Start Action section) - Start external program. When I moved the Solution to another location on my computer the problem occurred because it was searching for an absolute path to the executable file. Restoring the Visual Studio Project default settings (see above) fixed the problem. For your reference I am using Visual Studio 2013 Professional.
I had the same problem and unfortunately non of above answers worked for me . the solution that worked for me is :
right click on your startup project and select Properties - Debug and change "start external program: " to the correct path
Done!
Switch Target framework to 4.5.2 or something higher and bring it back to your original version (example: 4.5) then when you build, it will work.
You are not set the startup project so only this error occur. Mostly this problem occur when your working with more project in the single solution.
First right click on your project and "Set as Start Up Project" and/or right click on the start up file inside the selected project and click "Set StartUp File".
I also get this error quite often.
I solve this by modifying the code (doing a very small change), saving it, then building the solution again.
In my case I had added a project to a solution manually, where that project was targeting a higher .NET version than the rest of the projects that were referencing it. Strange... there would normally be a somewhat more verbose, literal and descriptive error in such cases.
There wasn't a real error but there was a warning that said as much.
Go to Project > properties > Debug Tab and set the Launch to "Project"
I had the same problems. I had to change file rights. Unmark "read only" in their properties.
So... it’s mid 2021 and I’m using visual Studio 2019 (version 16.10.2) which is the current version available, on a windows 10 pc.
I had to start a new project and following this steps solved the issue;
When at the menu that says “Create new project”
After you’ve selected your project template it takes you to another menu that says “Configure your new project”
On this menu there’s an option that says “Place solution and project in the same directory”.
By default this option was not checked, so I checked it and it solved the issue.
I had the same problem with visual studio 2015 , and I found that there is reference is marked so I just deleted it , maybe you can delete this reference or reinstall it again
What solved it for me was deleting the line
<ImplicitUsings>enable</ImplicitUsings>
from the project property file. It caused Visual Studio to generate a (useless) file with multiple global using directive.
I faced the same problem , but in my solution i had many projects so in the solution configuration the start up project was by mistake a class library i changed the startup project and then i worked like a charm
right click on the sln => common proprties => choose right startup project .