Why do my T4 templates sometimes append a number to the output file and sometimes not? For instance, in one case I might have a template file called Foo.tt and I'll get an output file of Foo.cs. In other cases, I'll get an output file of Foo1.cs. In every case, there is no other Foo.cs file that might be causing it to append a number. In other words, it is definitely not the result of any obvious file name conflict.
I'm a deeply anal retentive developer, so I'd sure love to know how to get rid of that useless numeric suffix.
This happens when Visual Studio gets itself confused and briefly decides that it can't use Foo.cs as the output for some reason (usually hallucinatory), so it will use Foo1.cs instead, and then insists on remembering this setting.
The fix is to open the .csproj file in a text editor and locate the Foo.tt entry. This should have a sub-element called LastGenOutput. Change this back to Foo.cs, save the project file, and reopen it in VS.
And then -- sigh -- wait for it to happen again. You can see http://social.msdn.microsoft.com/Forums/en/linqtosql/thread/0c0f77a6-d712-43d2-a990-555df7960123 for more details, though nobody seems to be able to explain what causes VS to get into this state or how to stop it doing so...
#itowlson's answer really helped me out, but I discovered a slightly simpler workaround that I thought I'd share.
If you have:
Filename.tt
└── Filename1.cs
Just rename Filename.tt to Filename2.tt:
Filename2.tt
└── Filename2.cs
And back to Filename.tt again:
Filename.tt
└── Filename.cs
Voilà.
I've discovered something in VS2019 that might explain one potential cause of the issue.
In the CSPROJ file, VS expects a TT file be included using <Content Include="Generator.tt"> tags. When adding a TT file to a project via Cut/Copy/Paste using the contextual menu items in the interface built into VS, VS may sometimes use the wrong XML tag, such as <None Update="Generator.tt">. This will be despite the fact that if you open the Property sheet for the TT file, it will show 'Content' as the build action.
Open the CSPROJ file, and if you change the <None> tag to <Content> and also the Update attribute to Include, then restart VS, the issue appears to go away.
Related
I just hit a brick wall with xCode not wanting to parse my Info.plist file. I've replaced the file several times with older (identical) versions of the file that I had previously backed up, and I'm still getting the same error.
Here is the complete error message:
couldn't parse contents of '/Users/...Info.plist': The data couldn’t be read because it isn’t in the correct format.
I'm clueless on this one. I'm using xCode 5.0.1, Mavericks
This is one of the best way to detect on which line the error is occurring.
Just go the directory where the plist file is present then write this command on terminal->
plutil filename.plist
Another cause of this issue can be from attempting to put URLs (really just slashes etc.) in your app-Info.plist.
Get around it by simply raising the -traditional flag inside of the Info.plist Other Preprocessor Flags option in your project build settings.
I think you have used source-control tools, you can use basic text-edit tool without Xcode to open this plist, command + F to find "<<<<<" or ">>>>>", then you will probably find error string such as:
<<<<<<< .mine
>>>>>>> .r605
select the correct string, and delete the other one, error is resolve!
Looks like replacing the file with a backup, then deleting the derived data for the project in Organizer was the cure. Hope this helps someone else later on.
I personally ruined the file when git merge raised conflicts. .plist is an XML file and git conflict added <<<< and >>>> in there to tag the differences.
Find the .plist file in Finder (in one of your project's folders). Open it in a text editor, find the lines that don't look like proper XML, remove them and be sure to remove the duplicate XML line/node (due to pre and post git recorded changes).
This may also simply happen because you have moved the Info.plist file into a new folder, or removed it from a folder (basically, if its path changed).
Go to Build Settings and search for "Info.plist file". Edit the value. For instance, if you have moved your plist file from the main folder to a subfolder called Resources, you will have to do the following change:
Before:
TargetName/Info.plist
After:
TargetName/Resources/Info.plist
When building for iOS, the Info.plist may be corrupted whenever Default Orientation is set to Auto Rotation. The Info.plist file is created properly on the first build, but subsequent builds results in...
<key>UIInterfaceOrientation</key>
<string></string>
</string>
... at this point Xcode fails to build the project.
I was having the same error, and realized the issue was that I had a URL (e.g. http://example.com/something) as a value in my Info.plist, and I just switched on pre-processing for it (without the -traditional flag). Apparently Xcode will treat the // as a comment marker, and omit the rest of the line.
A work-around I found is to embrace the pre-processor, like so:
http:/${}/example.com/something, which breaks up the // by putting an empty string substation in the middle so it doesn't look like a comment to Xcode, but after pre-processing it's back to a normal URL.
This error comes whenever Xcode preprocessor is not able to parse the info.plist file.
So to find out the error in the specific line do the following steps :
Open your project.xcworkspace in Xcode
Go to the project's navigator
Inside your project click on the info file, if an error exists then it will popup the dialog with the line number where the error exists
You can see the below image of the popup dialog for reference, which is in my case was showing the error on line 35
Hope this will help you or somebody else. Thanks!
Happy Coding :-)
Apologies. I am sure I should know where to look to deal with this but I do not:
The error below has appeared in my solution. I am not aware of why.
The item
"obj\Release\ScruffyDuck.AirportDesignEditor.MainForm.resources" was
specified more than once in the "Resources" parameter. Duplicate
items are not supported by the "Resources" parameter. Airport Design
Editor
Perhaps someone would be kind enough to put me out of my misery and tell me where to look.
Thanks
OK I found it. I have no idea how it happened. However it might be useful for the future. MainForm has a number of files containing different parts of the class. The main part has all the designer code and so on. Somehow a .resx file got created on one of the partial class files along with an InitializeComponent() method. Removing the extra .resx file got as far as reporting the duplicate method and removing that allowed the solution to compile again. It seems that though the file names are different (the error was in MainForm.EventHandlers) the two resx files are treated as the same even though they have different names.
I am now getting some exceptions but at least I can get the code running in the debugger again.
I think you'll have to open your .csproj file, and look for that file name. It sounds like ScruffyDuck.AirportDesignEditor.MainForm.resources is appearing more than once. Just remove the duplicate node (.csproj files are just xml).
Just remove obj directory from HD manually.
Clear solution from Visual Studio (Right click on project in SolutionExplorer and select "Clear")
Rebuild solution.
Cause could be a fault of generated resource file, due some conflicts happened in your project.
Should work.
Regards.
I've run into a problem with VS2010 (it also exists in the latest version, SP1 (10.0.40219.1)):
Add an existing Word file to the "Solution Items" and check this new file in.
Check the file out for editing
Double click on the file and edit it in Word (just make some minor changes)
Save the file (CTRL-S)
Now the file is removed from the "Solution Items" in Visual Studio (you may have to repeat the editing and saving a couple of times)
Update: I'm using Visual SourceSafe 2005.
Despite my research efforts I haven't really found anything on this issue apart from this Microsoft page, and I'd like to know whether there is a way to prevent this problem from happening.
Any ideas are more than welcome, thanks in advance.
G.
After further investigation I think I found the reason behind this behaviour and a workaround.
Please also note that the behaviour described in the original question only occurs for files that are added directly underneath a solution or to a folder that is directly underneath a solution.
The reason
I'm not sure whether the following is 100% correct, but the main point is how Word (and probably other MS Office apps as well) saves an existing file:
Save the current version of the file to a temporary file
Rename the original file so it can be used later in case something goes wrong
Copy the temporary file to the location of the original file, using the original file's name
Delete the original file (that was renamed in step 2)
Visual Studio picks up that the file doesn't exist (for a very short time though) and removes it from its tree and the .sln file. This can also be reproduced by manually adding any kind of file, checking it out (if not checked out), renaming it to a different name and then back to its original name => file is no longer shown in Visual Studio.
The workaround
I've created an empty project template following the steps on Microsoft's site. I also set the output to "Class Library" so that the project would compile even if no static main method exists. This template can be used to add a "Documentation" project to an existing solution. Underneath this project you can add files and edit them as you wish, as Visual Studio behaves differently and does not remove the file when it is saved in this constellation.
Obviously this approach is still not very satisfying or elegant, but I hope that it may be helpful for others who might run into the same problem.
G.
I've run into the same issue. I simply undo changes for the solution after I've closed the document file and the solution files will be as they originally were before your document changes.
XCode2 had this beautiful feature: you put the cursor on a line with a #include <file> and execute the open-quickly command (command-shift-D) and it would open the file. I can't get it to work for me in XCode3.
I have something like this
#include <folder/subfolder/HeaderFile.hh>
and when I put the cursor on this line, and open the open-quickly dialog, it automatically fills the search window with
folder/subfolder/HeaderFile.hh
but doesn't find anything. If I then remove "folder/subfolder/" then the dialog will identify HeaderFile.hh and I can open it up. But this extra deleting is so much slower just the three-key command-shift-D opening I was used to with XCode2.
If I give it the full path to this file in the search window, then it finds it:
/Users/andrew/myproject/src/folder/subfolder/HeaderFile.hh
this path will find the file. Again, I don't want to spend all my time typing out the full path.
I created this project as an external build system, and I think that's related to the problem; the xcode project lives in
/Users/andrew/myproject/xcp_dir/
and I want it to search in the "../src/" directory so that the partial path I give it (which is already present in the #include) will match the file I want to open. In XCode3, I had to create the project in the xcp_dir directory; in XCode2, I could create the project directly into the existing myproject/ directory -- maybe that's why the search is failing?
I read on a previous thread (which never answered the question) that I should set the HEADER_SEARCH_PATHS option. I tried this (setting the option to /Users/andrew/myproject/src) but it did not work.
I don't have any sense of what other options (like the HEADER_SEARCH_PATHS option) are availalbe, so if you know which one I have to set, I'd love to hear it.
Since this is an old question I'll answer it for Xcode 4 instead of 3.
As far as I know Open Quickly doesn't use anything like a search path. It seems to have use the project's codesense index and will show results from that. Querying the database doesn't have an notion of file paths, so the workflow you describe just won't work anymore.
However that's okay, because there's a better solution: Just ⌘+click on the include line and the appropriate file will be found using the same rules as the compiler uses, and opened. If you want to open the file up in an assistant, another tab or window, you can use ⇧⌘+click instead, and you'll get a little UI for easily selecting where you want the file opened.
You can also use these shortcuts to go to definitions for any identifier.
If you don't want to use the mouse you can use the command "Jump to Definition" which has the shortcut ⌃⌘J, or ⌥⌃⌘J to open the definition in the assistant editor. This also works for both normal identifiers and #included files.
Is it possible to open a project in Visual Studio 2008 without opening all the files that were previously opened last time I had the project open. I have a habit of keeping many files open as I am working on them, so next time I open the project, it (very slowly) loads up a bunch of files into the editor that I may not even need open. I have searched through the settings and cannot find anything to stop this behavior.
Simply delete the .suo file.
It contains the list of open files.
A bit of research turns up the fact that you can do it with a macro:
Create a new macro (or use an existing one). You should see a module called EnvironmentEvents in Macro Explorer. (For details, see here.)
Open the EnvironmentEvents module.
Put in this code:
Public Sub CloseDocsOnExit() Handles SolutionEvents.BeforeClosing
DTE.ExecuteCommand("Window.CloseAllDocuments")
End Sub
Save and Build the macro.
Open a whole bunch of documents in your solution, then close Visual Studio.
Yay! No more open documents!
(Note: Despite that it says SolutionEvents, it also works if you're working on a project that doesn't have a solution.)
I never realized how much that annoyed me as well! I haven't been able to find a setting, but in Options > Environment > Keyboard you can bind a shortcut to Window.CloseAllDocuments. ALT+X was unbound for me so I just used that. I'm interested if there's some hidden setting to automatically do this on solution exit though (or load).
Edit: Totally read the question wrong at first - ignore my first (now gone) answer. :)
I changed the keyboard mapping for CTRL-SHIFT-C from bringing up the Class View to closing all document windows - something I use several orders of magnitude more often - and then I just clear my workspace before closing a solution.
Try the following:
Close the program after closing all files.
Make a copy of [whatever].suo
Open the solution again, open some files, and exit.
Copy (don't move) the old .suo file over the one that was just generated.
Make the .suo file read only.
If you have a repository you might want to check that file in.
I suggest this because I was having the reverse problem, where it wasn't opening my old files automatically, and the cause was a .suo file that had been checked into the repository and was (for some reason) not being overwritten by Studio. The file wasn't even write protected.
I was hoping for something a little more automatic. VS will create a new .suo file every time the project is saved. So I would have to delete that file every time I open the project. I also don't want to have to remember to close all the files before closing VS.
Other IDEs that I have used have similar functionality, but also make it rather simple to turn on/off.
Thanks for your help.
Or you can close all open document from the Window menu before closing VS.
In Visual Studio 6.0 (VC++), the procedure is slightly different.
Delete the .ncb file (located normally in the same place as your .dsp or .dsw files).
The only way works for me is : change the project location and again reopen the solutions form there. :)