Git with Visual Studio 2015 not allowing my partner to create a new project - c#

Git, used with VS 2015, as the title indicates, is having issues; we're creating a large application that so far has 16 projects for separation of concerns.
The majority of the time, git is fine, although sometimes it does untrack things we don't want it to. Probably, it's just because we're so busy doing things, we don't realize sometimes that new files aren't always tracked by Git by default. Whatever.
But now, my partner has created a new project for our API services, and it untracks the project and class files; but when he adds them back into the commit and commits the entire thing, it will either not let him commit, or it will say it's committed, and then I cannot get it from syncing with him. It's like Git just doesn't want the project to exist.
I can upload projects just fine. I uploaded a new project and added references to a couple of our other projects, and committed, and everything worked fine when he sync'd up. But for some reason, he can't create this one project. We're not sure why.
And, we can't seem to access the command prompt on his machine because he has a separate drive for his data, he stores everything on his D: drive. Command prompt will not access his D: drive for some reason. We can probably look up that issue and figure it out quickly, if we need to use command prompt with Git to fix this issue. But we're simply wondering why Git is doing this and what we can do to fix it. We have researched it and found nothing.
The only proposed solution was using the command prompt with Git to use git add -u and add the files manually, but we'd need to add the folder design as well, not just individual files. We need to add the entire project and directory.
Any ideas?

Related

VS for Mac not showing local git file diff

I typically develop on Windows, but I've recently been using the new Visual Studio for Mac 2022 release, which has a "Git Changes" window. Whenever I open my git repository in VS, in the Git Changes window it will say something like "this directory doesn't contain a Git repository" and offers to initialize one for me (which of course does nothing). From Googling around, it seems to be a "safe directories" issue, which I can get around with adding the directory to safe directories in Git config. This isn't always respected though, and half the time it will only show if I go to Git -> Commit or Stash, and then it will realize I'm in a git repo.
The bigger issue is that it almost never shows me the local file of the diff, like in this picture. It seems to know that there is a diff though, as you can see it does say "2 lines removed" at the top. Sometimes, randomly, if I click around and change the views it will actually show the correct diff. But it's impossible to reproduce, it will just randomly decide to show it or not. I would say maybe 1 out of 20 times it will work.
It's also showed me incorrect information in the Git Changes window, such as saying I deleted 6 local files, but I didn't, and once when I double-clicked a "deleted" file in the window, it opened the correct diff! You can see it falsely flagging the files as being deleted here.
I've tried restarting my Mac without any luck, and I've messed with the file/directory permissions quite a bit but it has no impact on how VS acts. I couldn't find anything in the logs that seemed to mean anything. I also tried re-cloning the git repo and that didn't solve it either.
I also can't seem to find anyone else with this issue. I'm on the newest version of VS for Mac, with macOS 12.5.1.
Any ideas??

How do I build code out of a tutorial repo that has many examples (in Visual Studio/C#)

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!

Problems adding Visual Studio 2015 project to Source control

I have a solution with two projects in it. One of them is added to source control, but the other is not. They are in different folder paths (let's say project that is added to source control is in PATH-TRACKED, but the other in the PATH-UNTRACKED).
What is a correct way to get that untracked project to the git repository folder PATH-TRACKED so that I don't brake my solution? By moving to the PATH_TRACKED I could add it to source control, but then I would brake the references to that project, right? What is the recommended way to do this task?
As a result I want to have both projects in the same repository
Git is quite good at following file because its file detection is based on the content. So, if you don't modify the content of the files in the same time you move your files, their should be no problem.
So, move the untracked folder into your repository and move the other directory in a sub folder, if needed, and all should be go well! Just do it without introducing other changes (especially in the content of the files). Do it in one or two commit if you find it clearer...
Anyway, if the commit you end with do not suit you, git reset and do it again (or even better, amend it)... No need to worry. Here, git is not the problem but perhaps you will have to update some files (sln or csproj) to make all that build :(

Error on creating new Git project in Visual Studio 2013

I'm using Visual Studio 2013 with the MS Git plugin. I'm trying to add an existing project to source control on my machine. The project is an empty project with one file. The path to the project solution is C:\_Projects\HelloGitWorld\HelloGitWorld.csproj - according to the git settings, I created the default repo location, but it doesn't seem to be storing the repo there (I tried this for other projects as well, and it created the repo in the same location as the solution).
So I basically right-clicked on the solution and chose 'add to source control'. This is simple enough, and as soon as I do that, I get:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
I realize you can do this through git bash as well, and I will eventually move onto that, but right now I just want to add a local repo for this. Why won't it let me? Where is this trying to create a path that is too long?
Even though you create a project under your "default repo location" this does not mean a Git repo will be created for you. You need to create (or clone) a Git repository BEFORE creating a project/solution, or use the "Add to Source Control" option to ensure a new repo is created for you.
The "default repo location" is not a Git repo, and a solution folder is not (by default) a Git repo.
The real purpose of VS's "default git repo location" is so that VS tooling can locate any repositories you have cloned locally. It will search the immediate folder you specify and (I believe) any sub-folders. Any folders recognized as Git repository roots will then appear in the list of Repos in the 'connect' page of Visual Studio UI.
If you want to use the command-line this page on git-scm.com has a small snippet which shows how you could create a folder and initialize it as a git repo (locally.) Here is an example showing how to initialize your solution folder as a new, local Git repository from powershell (with msysgit installed):
set-alias git "C:\Program Files (x86)\Git\bin\git.exe"
cd "C:\_Projects\HelloGitWorld\"
git init
git add .
git status
From there you can launch visual studio, load your project/solution and see that git integration is now working as intended. The same set of commands can be executed from a CMD shell, but you will probably have to specify the full path to git, or just use git bash (which may be obtuse for you if you're not accustomed to using unix shells.)
If you don't want to use a command-line tool you can use Visual Studio Tools for Git and select "New.." from the "Connect to Team Projects" panel (thanks to Edward Thomson for pointing this out), or use a third party tool such as TortoiseGit. This will simplify the creation of a git repository without requiring you to understand how Git works, nor how to work with a command-line. For most simply scenarios you can rely entirely on Visual Studio Tools for Git. No need for anything third-party.
I use visualstudio.com and github.com for project hosting, as well as bare (private) repositories on a secure SAN at my home (since, in the end, you can't trust anyone anywhere with your private works. I don't care what people say.) You might find this article on saintsjd.com helpful in deciding if a bare repo is what you're really after, and this guide on stackoverflow to see how to create one yourself.
Let me know if I can clarify anything, or if you need some examples.
You've mentioned MS Git plugin - why you use it when VS2013 supports Git by default?
I'm using standard VS2013 Git integration + Git for Windows to sync my solution with Bitbucket and it works fine.
I also saw this strange default repo location setting, but all Git repos are actually placed inside .git folder under my solution when I use a solution context command "Add to source control..." (at this point you may create your Git repo from scratch). And actually .git folder + .gitattributes and .gitignore files are your local git repo which you may or may not sync with external hosted Git repo such as Bitbucket and Github. If you want to remove Git binding for you solution just remove mentioned folder and files.
As for the long path error you may check your actual solution path in Solution Explorer (select Solution root element and press F4).
Here are couple of links which may help you to get started:
Walkthrough for adding solution to Bitbucket repository (I followed it myself)
Visual Studio 2013 with Git (official)
It's worth mentioning here that if you're looking for a free hosted private Git repos then you might want to go on with Bitbucket (private repos are free for teams up to 5 people). If a small fee for private repos does not distract you then you might want to go on with Github which is the biggest Git repos hoster. Disclaimer: I'm not affiliated with Bitbucket and Github in any way, it's just a result of my personal investigation.
Also I must admit that I'm not a fan of command line tools so my solution is good if you don't like them also.

TFS on VS2010, merging code issues

Recently we have been having problems with TFS and our code base. We have a section of tests that use Webdriver, and a section that use Coded UI. Lately, we've been having problems merging our code after a new build has been pushed out. Some folders show up as a white outline of a folder, which we can right click and select "include in project". We also notice some files missing, and we can't "get latest" to grab them. We have to go some round about way to do it (shelve code, delete local files, get latest, merge code). Even when we do that we still have some issues.
But the main issue we are having is that our Coded UI maps are breaking. Instead of being the normal structure such as:
.uitest
----.cs
----.designer.cs
When we merge in the new code, the UI maps break out like:
.cs
----.designer.cs
.uitest
I opened the .csproj in notepad++ and noticed that both the .cs and .designer.cs files no longer have a dependancy of the .uitest file. Now the .cs file has no dependancy, and the .designer is dependant on the .cs file. We can fix it with relative ease, but it keeps breaking in every build and we have several maps we need to fix. What exactly could the problem be here? Also, referring to my frist problems of files not being included in the project, what could the issue be there?
I asked the same question on the MSDN forums, but the suggestions I have received I have already tried, like creating a new workspace since the other might be corrupt. Still didn't work.
Thanks in advance
Edit: Had a suggestion on the MSDN forums to run VS as administrator. That didn't work either. Not really sure what could be causing this issue. It doesn't seem to be causing problems for everybody because some new builds cause issues for some people but not others. Some more info would be I run on Windows 7 64bit and Visual Studio Ultimate 2010.
In the past I've had issues with TFS that sound similar, 2 of our developers seemed to periodically create problems when merging files into the data store, folders and files would show as not included while the project file would make it in (breaking everything after get latest). Eventually the problem went away but we never truly found the source. I believe it had something to do with our network - maybe a switch issue in combo with the way we mapped working folders to network drives pointing to a shared dev server. Also one of the workstations seemed to have a problem with windows explorer not seeing file updates on the dev server share... developer would have to hit \servername\C$\sharefolder then hit his mapped network drive again before updates would refresh. (And his check in's created the most problems) ... we ran VS2008, TFS2010
Just some ideas...

Categories

Resources