Visual Studio - Renaming Files From Uppercase to Lowercase - c#

Short Version
I found myself losing alot of time renaming + including files in my Xamarin.Forms Projects because any change from Upercase to Lowercase (or vice versa) only in the files, will result in no change what so ever in the Project file, so i have a few questions:
Is there an option in Visual Studio that makes it take into account file renaming from Upercase to Lowercase? (See Edit Below)
What's the best way of changing alot of files from Upercase to Lowercase without delete/re-adding them?
Is renaming the file includes in the .csproj directly a Good Practice? if not, what is the best for this kind of scenarios?
Longer Version + Adicional Info
I had to include over 2000 images (Android + iOS and their respective sizes). So i started copying the files into the correct directory and include them in the Mobile Projects, the problem came when i already included the files in the project and some of the files had Uppercase letters that i haven't noticed before, so i made changes by hand to all the files, when i noticed that those changes weren't reflected in the Solution Explorer/Project File, i tried manually and got this error:
Edit: It seems this issue was apparently resolved in VS2019 arround v.16.1, but only if the file wasn't renamed externally. Since i did that i got this warning. This anwsers my first question.
And one solution that i found was renaming like: Foo.png > fooo.png > foo.png
But that would be exponentialy time-consuming by the number of files i had to edit, so i made this piece of code:
string filepath = #"C:\Users\(...)";
DirectoryInfo d = new DirectoryInfo(filepath);
foreach (var file in d.GetFiles("*.png", SearchOption.AllDirectories))
{
if (file.Name.Any(char.IsUpper))
{
File.Move(file.FullName, file.FullName.Replace(file.Name, file.Name.ToLower()));
}
}
What it does is basically create a new file but with Lowercase, that means i still have to Remove the old References and Include the new Files. This doesn't seem right since a simple rename would do.
What's my go to option here?

Windows as operating system is ascendant of the operating system where there was no difference in lower and uppercase. As such at today's state Windows treats the files with same letters as the same though technically it can remember and display lower and upper cases in file names.
Overall it means your request is not natural in Windows. Maybe someone can provide you with some hack, but if you want to resolve this problem quickly move your project to the Mac where this works differently at the operating system level, perform your operation in Visual Studio for Mac and then you can continue to use Windows if you prefer.
EDIT: Actually I can tell you one hack for Windows. First rename file to whatever you want (like add 1 at the end) and then rename it to the desired file name. It will work properly.

I had the same issue. In my case the files were in the .csproj (Project File) with lowercase name. Removing the affected lines from .csproj fixed the problem.
In Visual Studio 2019 -
Right click on the project name in Solution Explorer -> select "Edit Project File"
Find the offending file under ItemGroup, you can either remove the line or edit the filename. I have not had any side effects by removing the file as I know what I am doing, your mileage might differ.
Just incase cut and paste the delete or rename before hand in Notepad in case you want to go back, Ctrl-z works too :)

Related

Build action is not supported

No code, since it's not a code problem, rather a visual studio one.
I've searched this problem up a bit and found people saying they had this problem, not really specifying how they got it, and most people answering "you should set AndroidManifest.xml's build actions to none" without any explanation of why this would work, which, well won't work for me since it's already what I have and I'm getting the error anyway.
How I came to have this problem:
I made a few files, file1, file2, file3, in my assets directory.
I would then read them with a streamreader. This worked.
Fast forward a few weeks, I decide to rename them, through visual studio, to file1.txt, file2.txt ... etc.
When I compiled/launched it on my device, it did not work. An exception on streamreader told me the file wasn't found. And before that I had 3 errors "#(Content)build action is not supported" for each of my files.
I assume the problem lies in the build actions or possibly the way android behaves with some specific files? Either way how could this have changed by changing the file format? I made them .txt files for clarity purposes, I didn't expect everything to break down after that.
Ontop of that, I could not revert it. I removed the file extensions, and I still have the same problem now.
What should I do to have my files in the assets folder properly deployed on my machine just like they used to ? Is it related to the build options?
Thanks in advance.
As highlighted by Jason in the comments above, the build actions for android assets should be AndroidAsset, which got changed after I renamed them. This menu can be found on the properties of the file.
https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/resources-in-android/android-assets?tabs=windows

Source file in CSC cannot be found

After a struggle with creating a database (first with an entity framework, after without), we have a database (and an EntityModel_HFFContext file we don't use, it's not connected). Normal work proceeded, and I installed a NuGet-package for an MVC sitemap.
From that moment, the project worked fine, but after a couple of days two warnings came up about two files missing: "The parent file, 'EntityModel_HFF.tt', for file 'locatie.cs' cannot be found in the project file." ("HFF" is the project name in here) and then those multiplied themselves into errors: "Source file 'locatie.cs' cannot be found" in a CSC file I cannot find.
These two files ('locatie.cs' and 'klant.cs') are not in any view, but somehow they are displayed outside all folders, saying they do not excist (see this screencapture). I have tried to delete those files manually, but that did not have any success. I have tried some other ways too, but that resulted into the complete deletion of the database, so now I am somewhat desperate.
I have no idea where to look and what to do, to get rid of these two files (or probably references to these files, since we don't use them at all), so I don't have these errors anymore. Has anyone of you have a clue of where I need to look (e.g. where this CSC file is) and what I need to adjust to fix this?
Maybe it can be useful to know I use Visual Studio 2013.
Update
I fixed the errors by unloading the project, editing the .csproj file and commenting out
<Compile Include="klant.cs">
<DependentUpon>EntityModel_HFF.tt</DependentUpon>
</Compile>
(and the other one too). Now these errors are gone - is this a safe way to do this?
The reason why you get the error is because when you deleted the locatie.cs and klant.cs file, you didn't remove them from the project solution itself, therefore, Visual Studio is expecting the file to be part of the project but is unable to find them, which explains the yellow warning signs.
Like what you said, all you have to do is to remove the files from the solution as they no longer exists. So yes, it is safe to comment out that portion in the .csproj file.
Although, I would like to mention that you didn't have to go to that much trouble, all you had to do was to delete the file in your solution in Visual Studio, since they no longer exists anyway.

TortoiseGit / Winforms: Resolving Resource.resx When Merging

I am fairly new to TortoiseGit. Wondering, if I get a conflict on a .resx file, how do I resolve it during a merge? For example, I could select "using theirs" off of the menu, try to do a pull and push, but is this the right approach? Can I somehow use theirs and rebuild it with my project changes? The differences (as well as mixed up contents compared to the respository) are many - to many to do a real merge. Thanks for looking?
This is an old question that has not been answered. However resolving conflicts in resx files is driving me nuts. The main issue seems to be that resx files can be changed randomly when updated. Visual Studio does not care about the order. As a result a lot of trivial 'conflicts' can arise because of elements being in different places in the two resx files.
I found the answer is to sort the resx files by name attribute before the merge. This article explains how it is done and provides a simple command line tool. The author refers to how it can be integrated into different diff/merge tools. His example is Beyond Compare 3 (which I use) and this article gives instructions on how to do the integration.
I tried this and for the first time I managed a merge of branches with GUI changes without loss or hair or hours of manually repairing things in Visual Studio.
I hope this answer is relevant and may help folks as it helped me
My solution is a bit hacky but it takes care of the Resources.designer.cs file too.
VS auto generates Resources.designer.cs from Resources.resx so i just fix the later and regenerate Resources.designer.cs
Typically I do the following stages:
close VS
command line : git merge (merges src branch to current)
i see the conflict in Resources.resx
delete Resources.Designer.cs file (it will get regenerated later)
open Resources.resx with some resolve tool (i just use notepad++)
resolve the conflicts manually (in notepad, typically i search for "<<<", remove the "<<<","-----",">>>>" lines add the missing and save.
open VS with the project, it will complain about missing Resources.designer.cs file.
double click Resource.resx, add at the end some fake row + save (this recreates Resources.designer.cs)
del the fake row i created before and save.

rename class with file name in one step in Visual Studio

I am a long year Java programmer, but currently I code in C#. I am accustomed, that when I change filename, also the class name changes and vice versa. This doesn't work in my Visual Studio. I must rename the class name and file name separately, and it's sometimes annoying for me, because I always forget on it, so it results to that I have different class and file names.
Is there option in Visual Studio to put the renaming in one step?
Renaming a file works fine - it'll offer to change the code to match:
If you rename the class, then - indeed, this doesn't happen by default. There is no actual need for the two to match, note. But ultimately, rename is only an f2 away.
As of Visual Studio 2015 Preview 5, the "Quick Actions and Refactorings" context menu contains a "Rename file to [class].cs" command.
It seems to not work when the copied file is in the same folder and the class name is the same (which it will be if you just copied the file). I think the reasoning may be that rename doesn't descriminate between a class in a newly copied file and the original (See comment below by #xMichal).
The quick solution is to copy the file (I use ctrl+drag) into a nearby folder, rename, then move it back.
Another option (which may be Resharper specific), is to rename the class (and constructors) in the copied file, then use the tooltip to electively rename the file to match.
ReSharper has the MoveTypesIntoMatchingFiles menu option on the Refactor context menu, and it seems to do the trick. Just that if you have more than one class in the same file, they will be moved also into separate files, but that should be a good thing in most cases anyway.
Install the awesome visual studio plugin called Reshaper.
It does that and loads of other nice stuff.
Free for 30 days then its costs but is definitely worth it.
If you 'refactor' something, the name will be changed everywhere where that text or name has been used so you don't have to follow up changing the name every time its been used. However, you cannot do that with objects beyond the project eg: file name.

SVN keeps corrupting files with "<<<<<<< .mine", how to fix?

I've got a Visual Studio C# project which is under version control (SVN).
I've always commited and updated the project without any problems. But a couple of hours ago Visual Studio throws the following error when I try to launch/rebuild the project:
Files has invalid value "<<<<<<<
.mine". Illegal characters in path.
I don't know how to fix this problem. What should I do?
That happens when svn encounters a conflict: You changed a file, the file on the server was changed and it cannot (easily) be merged automatically. You need to decide what is the correct solution now.
Subversion just adds the diff into your source file (and creates files next to it, called OriginalName.mine (unchanged) and OriginalName.rsomething (unchanged, server version)).
Fix the conflict and tell subversion that this is resolved.
just delete the obj folder and it will worked fine.
Remove the code that shouldn't be in the file throwing the error and remove the the three files with extensions .mine, .<somerevision> and .<some_other_revision>. svn updated files that now contain 'conflicts' and you need to resolve these conflicts by hand. Usually this means you edited a file, someone else edited the same file and checked in changes and you didn't pay attention when checking out the changed file.
Delete every thing you have in obj folder .
Remove your obj folder from svn version control . Because on every build it get updated and when other developer commit changes to solution SVN is unable to marge obj folder files and raise error
Files has invalid value "<<<<<<< .mine". Illegal characters in path.
Please read the Basic Usage chapter in the subversion book. It has a section about Merging conflicts by hand which explains the conflict markers you're seeing.
Removing the debug folders worked for me (see comment-not answer above).
I got this after moving 12 folders from one section of svn to a new section. So if you get this after moving a project and the error does not point to an actual file, this is likely your issue.
If you have AnkhSVN or VisualSVN installed resolving this is most likely as easy as right clicking the file in the solution explorer and selecting edit conflict.
This will open the changed file in your merge editor. (See Tools->Options->Source Control->Subversion User tools for AnkhSVN). With a good merge tool like the free to use SourceGear DiffMerge or TortoiseMerge, resolving the conflict is just a few mouseclicks away.
I have had this happen on a large scale where the files get marked resolved but the conflict metadata is still there. I wrote a regular expression for visual studio to find these, for instances where it is not feasible to simply revert the changed files.
http://www.codetunnel.com/blog/post/90/ever-merge-with-svn-and-mess-up-when-resolving-conflicts-read-on
I closed the IDE, then deleted the obj folder and restarted the IDE and rebuilt my Code. This worked for me.
Inside your project :
odj folder -> Debug -> project name.csproj.Filelistabsolute.txt(snb.csproj.Filelistabsolute.txt)
Inside the text file
>>>>>>>.mine and >>>>>>>.r150 occurs
to remove the things the program works
1)Just save your local changes whatever u have edited in the file
2)revert the file
3)update it from SVN
4)Paste your local changes
If you are using TortoiseSVN you should have a right click option on the file called Edit Conflicts. This should bring up TortoiseMerge which is able to read those obnoxious notations stuck into the file (really, to break your code so you KNOW there's an issue and don't blindly check it in).
TortoiseMerge will read it properly and present you with a 3-way merge. This was what I was looking for. Although it is true that it does also create the separate .mine and .rxxx and .ryyy files, and there are various manual and command-line ways to deal with all this.
Have a simple solution. just delete all file from debug folder and rebuild the solution, an error display on the screen "There were build errors. Would you like to continue and run the last successful build? click on "Yes" button. Now stop the program and run normally.

Categories

Resources