How to make copy of Visual Studio 2019 project? - visual-studio-2019

I have a Visual Studio 2019 project. Was asked to make trial changes. Do not want to alter current project. Is there any way to copy a project so I do not have to start over from scratch?
Searched here and other forums and documentation and cannot find solution.

Short answer: you can very simply copy the directory in which your project reside on disk. Open the new directory and double click on the .csproj file and you are now working in your new copy of the project. But, if you want to do that in a more professional and maintainable way, please read on...
The best way to do that in a more robust way is using Git.
In the bottom right corner of Visual Studio find the "Add to Source Control" command, click it, then choose Git. Now the command says "master", that is your main "copy" of the project: in Git, this is called your main "branch".
Now click on it, choose "New branch", give it a name (e.g.: trial), leave the checkbox "Checkout branch" checked, then click on "Create branch". Now the command in the right bottom has changed to "trial".
Now you have another copy of your project: you can work on it, save your work on local disk. When you are ready to save it in Git, press the pencil icon, that is located in the bottom toolbar, on the right, near the command you used before (the number near it shows how many files you have changed): click it, enter a "commit message", then click on "Commit all". Now you have saved all your work in the trial "branch" of your project in Git.
If you want to come back to your initial copy of the project, click on "trial", then choose "master", and voila... your are now working on the old copy or your project. You can switch between the two branches anytime, only remember that, before switching, you have to "commit" your changes, that is, save them in Git, as I explained above.
At some point, you may want to bring the changes you made in trial to master. To do so, when you are working in master, click on master (always in the bottom toolbar, on the right), then choose "Manage branches", then right click on "trial", click on "Merge from...", then click the Merge button: you have now brought the changes made on trial into master. The only problem can arise if you have changed a file both in master and in trial, and the changes are conflicting: in this case, VS will warn you, show you the conflicting changes, and you will have to choose which version of the conflicting changes you want.

If one don't want or can't use git, one can also copy and paste the project folder. Once in the new folder, Here is what I usualy do (I assumed the old project is named "projectOld" and new one "projectNew").
:
rename projectOld.sln to projectNew.sln
open projectNew.sln and change the following line in order to set the new project name :
Project("{C9CE8BB8-8B4A-11D0-5E31-C9100A0BC942}") = "projectNew", "projectNew.vcxproj", "{66F6A241-22E1-4941-6DA3-B6D9E7A8AF86}"
rename projectOld.vcxproj to projectNew.vcxproj
open projectNew.vcxproj and change the lines with the <!-- here --> comments
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
[...]
<PropertyGroup Label="Globals">
[...]
<RootNamespace>projectNew</RootNamespace> <!-- here -->
[...]
<ProjectName>projectNew</ProjectName> <!-- here -->
[...]
<ItemGroup>
<ClCompile Include="..\..\..\..\..\IncludePath(1)\ImplementatFile(1).cpp" /> <!-- here -->
[... up to last]
<ClCompile Include="..\..\..\..\..\IncludePath(n)\ImplementatFile(n).cpp" />
[...]
<ItemGroup>
[same thing for every ItemGroups] <!-- here -->
[...]
rename projectOld.vcxproj.filters to projectNew.vcxproj.filters
rename projectOld.vcxproj.user to projectNew.vcxproj.user
one can delete the Debug and X64 folders, they will be created again by mvsc.

Yes, with GIT branching you can create variations of a project easily.
But I think that was not the core of the question asked, because if you create a branch, it is kept separate.
I had a similar scenario where I needed a similar project in the same solution (code first database). A clone of the database project to start with and make some changes for a different database. So in the end I wanted to have 2 databases, not identical but similar, in the same solution.
Adding a new project in the solution and then copying the .CS-Files is possible but cumbersome because of the references and dependencies.
So what I did is:
Close Visual Studio
Open the file explorer and copy the entire folder (e.g. MyProjectA), rename the copy (e.g. to MyProjectB)
Rename the .csproj project file of the copied project MyProjectB. Then open it with a text editor of your choice, to see if you need to adapt anything (for example, project references if you moved it to a different directory level; they usually refer to a different project with a relative path, e.g. <ProjectReference Include="..\SomePathOfADifferentProject\SomeProject.csproj"/>)
Open Visual Studio, load the solution
In the solution explorer, right click on the solution, select "Add existing project...". Now browse for MyProjectB to add it as existing project
and you're done!
If you're using source control like GIT, make sure to check if the clone was correctly added (i.e. check if the files are tracked by source control).

I suggest you go with Project Template inside Visual Studio. You create a project template, store it somewhere, then create a new project by using the stored template. Here are more details
https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/ms247121(v=vs.100)?redirectedfrom=MSDN

Related

All the project files showing as Miscellaneous Files. Visual Studio 2017

I moved my Asp.net-mvc project from desktop to F drive and all the files are showing as miscellaneous files.
I've tried running the visual studio installer and modify to make sure that "Nuget targets and build tasks" are ticked.
I've also tried :
excluding the file
add existing member(adding the file again)
but nothing's working.
Same thing happened with my asp.net core web api when I moved it, it's working fine tho, getting data from server.
Hope you will solve your problem
Solution 1:
Create new project then paste all project contents in new created project.Restore Nuget packages then Build it.
Solution 2 :
Go to the file which are Miscellaneous inside Solution Explorer.
Right click those file'(s) and select Exclude from project.
Add Existing Item to project, you just excluded.
Probably your file property configuration is wrong.
Try this:
Right click over the File that has this problem
Click on Properties
Under Advanced -> Build Action, check if other than "Compile" is selected.
If so, change it to "Compile".
Properties Window

Visual stusio tfs file structure and excluded changes

I created a new project on tfs online. So I want to create a folder structure like this.
BuildProcessTemplates
src
docs
src and docs are created from source control explorer. I will add my existing solution in src and work from there. I have copied solution folder in but not detected by solution explorer. All files are in excluded changes. Why and how can I add solution?
That's the expected behavior.
When you copy files to workspace with windows explorer, the files will be detected under Excluded Changes.
You can click the Detected link under Excluded Changes, then select and Promote the candidate changes, the check in the changes.
You can also right-click in Source Control Explorer under src --> Add items to folder... --> Select the solution files --> Next --> (Select items from Excluded items to include if needed) --> Finish.
Please refer to Place an existing solution and code projects under version control for more information.

Certain Razor views not publishing

Using VS 2017 with MVC 5 Razor views. When I publish my application, a handful of specific views do not get copied over.
I'd discovered several SE questions on this same issue from back in the 2010-2011 timeframe. At the time, the issue was that Build Action in the file's properties was not set to Content due to a bug in some early RC which has since been resolved. Well, all of mine already do day Content for Build Action.
Any reason why only a small number of views are not making it in the publish?
As far as I'm aware, there are only 2 things that can cause this to happen.
As you say in the question, the build action for each view needs to be set to "Content"
The view files need to be included in the project file, so in the .csproj file there should be a line like this:
<Content Include="Views\ControllerName\Index.cshtml" />
Another one would be to set this in your csproje file. This was missing in mine, which caused it to make a precompiledviews.dll in my publish:
<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
Set it to false explicitely in order to publish .cshtml files.
Visual Studio -> Right click on "Views" in solution explorer. Click "Publish Views". This will set all the views to Content"
Depending on the version of Visual Studio, excluding and then including partial view or its folder may work or not. The most certain way to do it is to remove it from .csproj file and then include it again.
lets say _LoginPartial is not updated after publishing (especially if you have some razor code).
First open '.csproj' file, and remove
<Content Include="Views\Shared\_LoginPartial.cshtml" />
The build the project, and then add it again to .csproj, and rebuild and publish.
Another Solution From Visual Studio
right-click on the file and "Exclude From Project".
select the Project and click on "Show All Files" from Solution Explore (top horizontal menu bar on Solution Explore)
right-click on the file that Excluded and Click on "Include In Project".
This will automatically modify the .csproj file.

.csproj files not getting checked in to TFS

My problem is that in my scenario, I have a project with two parallel project files for different build targets. I have a ProjectName.WP8.csproj and ProjectName.WinRT.csproj, which essentially include the same files.
I am trying to check-in this solution (SolutionName.WinRT.sln) to TFS and I get no errors. All the code changes to the code in the project goes through, but when I check the actual state of TFS, the (newer) PorjectName.WinRT.csproj files are not checked in.
This is quite peculiar since it worked perfectly for the WP8 version. How can I support this kind of scenario?
(If it's not possible, how do I easily migrate my parallel project to another TFS project?)
Just had this come up myself. I had been working on a project for a few days before checking the solution in. During the initial check in for the project, only the most recent file edits were seen by source control. I was able to highlight all the files in the Solution Explorer and select Add to Source Control from the right click menu, but the csproj files themselves did not check in. To do this, I had to go into the Source Control Explorer and open the project directory. From within the directory, right click and select Add Items to Folder. Then you can select the csproj files and you're good to go.

Force TFS to detect changes

Seems like this should be something very simple, but I can't find how to do this...
I made a changes to several files spread within a repo by using a script that I wrote. Problem is TFS in its infinite wisdom does not think the files have changed. Aside from manually finding each file and clicking "checkout for editing" is there any way to tell TFS to just rescan everything and detect changes?
A Folder Compare (File->Source Control->Compare...) should do the trick. Select the top folder from where to start comparison, and select to compare with Latest Version. The result hould show files that are changed, and whether they are checked out or not.
TFS has a "Reconcile" command for this. See https://stackoverflow.com/a/22860674/932282 for a complete answer.
Local Workspace
You need to work with a local Workspace. Here's how to manage workspaces:
visualstudio.com: "Create and work with workspaces".
When adding or editing the workspace you click Advanced >> . Then you set Location: to Local.
Now when your script or anything else changes files outside Visual Studio, your workspace detects the changes automatically.
It also detects adds or deletes but you have to include them to your Pending Changes manually with the link under Excluded Changes
BUT BE CAREFUL. When adds or deletes get detected and you add them to your Pending Changes, the files aren't automatically included to your project. So you maybe check them in to TFS, but they aren't listed under the Solution Explorer.
Matt Burke has a fix for that problem:
mattburkdev.com: "Automatically Include All Files in Folder in Visual Studio"
To edit the Project file you rightclick your project, chosse Unload Project, then rightclick on it again and choose Edit. After you edited the project files save and close it. Then rightclick and chose Load Project.
But with that you also need to be careful, because the Project only searches for new files in these folders to include, when you load the project and not while you have the project open. So when some files get added outside Visual Studio, you just reload the project.
Server Workspace
But if you have to stick to a Server Workspace for some reason i got another trick for you:
FIRST:
Check out all Files that maybe have pending changes (better check out many files). Then go to Team Explorer -> Pending Changes and choose all files you just checked out. Then choose "undo changes". After this you get a message "Confirm Undo Checkout". This message ONLY pops up for the files, which actually HAVE changed! Press "NO" for each files or "No to All".
FINALLY: Under pending changes all files get removed from the list except the ones which have pending changes.
I hope I could help someone and you didn't have to search for this solution as long as I had to ^^
If any of your changes occured when you were offline, you can go to File > Source Control > Go Online, and all files will be checked for modification.
If none of the above work, you can also try to rebind your projects by going to File -> Source Control -> Advanced -> Change Source Control.
In Visual Studio 2015:
Source Control -> Advances -> Refresh Status
I had this problem a while age when i moved project from one pc to another.
the solution was to remove temporary files that TFS had created in solution folder.
Delete .vs and hidden $tf folder.
If no luck,on your local PC copy your solution folder to another, remove all files inside solution, get latest version from TFS server ,then from the copied folder just grab neccessary and edited files and put them back to solution folder (this will overwrite some files).
After all don't forget to check project mappings and if everything seems correct try right clicking on solution and 'Add to source control' option.
Dtsx file dropped in TFS folder was not being recognized.
On your Visual Studio (2015) home screen, click on the Team Foundation Server link. Make navigate to the correct branch.
On the window on the left side of the screen, navigate to the folder that contains your file. Expand the folder.
To the right of the folder you will see three dots. Click on those and then click on “ + Add File(s)”.
Choose “Upload Existing Files”. Then you can drag and drop your .dtsx files into the window and then click Okay.
Finally, you’ll have to do a ‘Fetch’ to add the files there. Then you need to do a ‘Pull’. Lastly, you can commit the change to remote branch.

Resources