VS .csproj still contains the removed cshtml file which blocks the Build - asp.net-mvc

I have removed a View from my Views folder in a ASP.NET MVC project. When pushing it to VSTS DevOps, the Build fails because it can't find the removed file.
I see that in the .csproj file the following:
<Content Include="Views\SiteSettings.cshtml" />
Which is the file I have removed.
Why is this stil in here? In my Repo the file is completely removed from the Views folder.
How can this be automated that it also removed the entry in the .csproj file?
Or am I missing something here?
UPDATE
File was still in my soluion, right click Delete and pushing the csproj file to vsts solved the build error.

This usually happens when after removing a project file you don't explicitly Save the project in Visual Studio. In this case Git will only realize the file deletion, but not the project modification itself.
I think if one uses the Git support of Visual Studio then the chance gets smaller, but when using an external tool like Git commandline or GitExtensions for example, then there is a high chance for this issue.
Unfortunately I'm not aware of any workarounds or solutions except for always paying attention to it.

Open you project .csproj and remove this line, save, push and publish again.
<Content Include="Views\SiteSettings.cshtml" />
this will fix your problem about missing file.

Related

Port Xamarin Android project to .net6.0-android

I have a Xamarin Android Project that I want to migrate to .net6.0-android so I can use the new versions of MvvmCross. I have tried the upgrade-assistant. It claims to only upgrade Xamarin forms apps. I tried try-convert and it only seems to use msbuild through .net5.0. Can anyone tell me the correct steps to do this migration?
Thanks,
Jim
I wanted to maintain consistency in my Git Repository, so here is what I did. I made sure my app used the new PackageReference (to do this, if your project has a packages.config, you can right click it and it will give you an option to migrate). I created a blank .net6.0-android app. I copied the contents of my original app .proj to notepad to keep track of what NuGet packages I had been using. I then overwrote the contents of my original app .proj file with the contents of the blank app .proj. I used Nuget to add back in the required packages. I had to delete AssemblyInfo.cs in the Properties folder and Resource.Designer.cs in the Resources folder. I deleted the obj and bin folders in the project folder. After that, I was able to compile and run fine.

How to make copy of Visual Studio 2019 project?

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

Visual Studio for Mac - AppResource.Designer.cs Not Getting Regenerated

Visual Studio for Mac Community 7.7.4 (build 1)
I went info one of my .NETStandard 2.0 projects and added a string MyLabelTitle to its AppResources.resx file.
I reference this string in my code like so:
AppResource.MyLabelTitle
This will build successfully and that is great.
However, lots of online forums, documentations, Xamarin forums, StackOverflow questions that I have seen state that AppResource.Designer.cs file will regenerate itself when you rebuild your project. Some suggest ignoring it in git as well.
To test that, I reverted back my changes (I am using git) from AppResource.Designer.cs so the end result is that:
AppResource.Designer.cs does not have my changes while
AppResource.resx file has my change in it.
Based on my understanding, rebuilding the project will pick up my change from AppResource.resx file and add it to AppResource.Designer.cs file.
However, building my iOS or Android project will now fail to build because it is referencing one of strings I added in AppResource.resx file.
This string is still present in AppResource.resx file but it wasn't regenerated inside AppResource.Designer.cs and as a result my project is unable to reference that string.
UNSUCCESSFUL ATTEMPT TO SOLVE
I thought that if I comment out the line of code referencing AppResource.MyLabelTitle, I should be able to build successfully and it did build successfully, but the string MyLabelTitle still was not picked from AppResource.resx file and re-generated inside AppResource.Designer.cs file. As a result, I cannot reference that string anymore in my code.
How to resolve this issue?
I suspect you also posted this problem on the Visual Studio for Mac community forum but will answer it here in case anybody looks here instead.
Visual Studio for Mac does not re-generate the associated .cs files for .resx files when building. It will re-generate the .cs file when the .resx file is saved in the text editor.
One problem here is that the .resx file needs to have unsaved changes otherwise the .cs file will not be re-generated.
Android projects will re-generate their Resources.designer.cs file on building. This .cs file is generated based on the contents of the various .axml files in the project not any .resx files.
There is an addin you can install which might help here. It provides a way to run all custom tools for the solution or project manually or when a build is run.
https://github.com/mrward/monodevelop-run-custom-tool
https://addins.monodevelop.com/Project/Index/380

How to change casing of a file that in under version control in Team Services Online?

To change the casing of a file name under Git we can use git mv command as specified here.
How do we achieve the same result in TFS?
We have a large collection of team projects (more than 150 team projects) and each team project is broken down into 6 Visual Studio projects at least, that makes at least 900 Visual Studio projects. Now in some of them we have Web.config file and in some of them web.config file. The point is, we're creating some automated QA/QC tools that need a consistent casing across our projects.
We want to change the lowercase web.config to PascalCased Web.config in all files.
We change file names on Windows, but TFS doesn't recognize it as change. We use Source Control Explorer to rename files there, and still it doesn't recognize the change.
We used tf rename web.config Web.config and it complains that the file already exists. We're stuck at this point. Any ideas?
Make sure the files are really in source control which are not prevented tracking by your settings (.gitignore or .tfignore ).
Try to get latest first (In Source Control Explorer right click the project node --> Get Latest Version ). Then rename the files. I tested on my side and the rename from lowercase web.config to Uppercase Web.config works as expected.
If that still not work, you can try to remap the workspace or create a new workspace to check that again.
Besides, you can also try to rename the file from web portal.

Cannot re-add view in a MVC4 razor project

I am unable to re-add a partial view after removing it. VS says the file already exists. I checked the .csproj and the .sln file for a reference but could not find any. I also did a clean get of all the source from TFS and still cannot add. Anyone know where to remove the old references or whatever blocks the addition?
VS is complaining that the file exists on disk, not in the project.
Delete it in Windows Explorer (or after clicking Show All Files) and try again.

Resources