Just setting up some quick class and object item templates and all is working great so far, but one thing I'm stuck on is the $safeprojectname$ template parameter.
I've added this as part of the namespace portion and the $registeredorganization$ is working fine
namespace $registeredorganization$.$safeprojectname$
{
public class $safeitemname$
{
public $safeitemname$()
{
//default constructor
}
}
}
And I've gone into the .vstemplate file and made sure ReplaceParameters="true" so the only thing I guessed at this point is the period between the company and project name, so I tested this out and just for laughs removed the period, still no go. Anyone have any insight as to why this isn't working?
EDIT: I'll accept Jared's answer as it answers my core question "why isn't it working?" but I am adding this follow up to show how I got my desired result. Instead of using the $safeprojectname$ or $projectname$ I found that using $rootnamespace$
namespace $registeredorganization$.$rootnamespace$
or depending on how your project is named:
namespace $rootnamespace$
works as I had wanted, just added this for anyone else who may come across this issue.
The $safeprojectname$ template replacement macro is only available from the New Project Dialog. It will not work for anything added as in individual item.
Reference: http://msdn.microsoft.com/en-us/library/eehb4faa(VS.80).aspx
Related
I have a Working and Compileable WPF-Solution in a which I needed to copy to another directory.
Now I experience the following Problem, which I nowhere found similar on the web:
In some Projects every UserControl I created, isnt compileable anymore. Somehow Terms like DataContext or InitializeComponent() "do not exist in the current context".
Usually this is a case of wrong namespaces, or classnaming between the xaml and xaml.cs. As my code is all compileable in the original repo, this can not be the case. I've also checked that build action is set to Page, which is also a common issue in this case.
As I've found out, even newly created UserControls have the same problems. So I compared the projectfiles from the source and targed destination, which seemed to have no difference at all.
At this point I'll ask the community. Have you ever experienced a similar problem? What do you think i could check, too?
Thanks alot.
In my case there's been a reference inside my project which was wrong but that wasn't reported.
I solved my problem with readding all my references even if they were meant as correct.
Check the x:Class property on the pasted UserControl and make sure it matches the fully qualified class name of the codebehind
for instance in you have the following in MyUserControl.xaml.cs:
...
namespace MyApp
{
public partial class MyUserControl: UserControl
{
public MyUserControl()
{
InitializeComponent();
}
}
}
Then make sure the you have x:Class="MyApp.MyUserControl in your MyUserControl.xaml file
I have a class named Print.cs that always stubbornly opens in Design View, when I need to see its Code View (F7). It also has a different icon to the rest of my classes in the Solution Explorer.
I've looked in the Properties and can't see anything relevant. I've also tried deleting and re-creating the class, but the icon comes back.
How can I force Print.cs to always open in Code View?
(Click to enlarge)
NB: disregard the green squiggly line, it's just a warning that unreachable code was detected.
Taken from the suggestions from #LarsTech and #OrkunBekar, since neither posted this as an answer - this works:
[System.ComponentModel.DesignerCategory("Code")]
Added between the namespace and the class, e.g.
using System;
using System.Collections.Generic;
...
namespace POS
{
[System.ComponentModel.DesignerCategory("Code")]
public class Print : PrintDocument
{
...
}
}
Try right click on the file -> Open With -> CSharp Editor (remember to set it as default).
Funny enough, it was totally other thing in my case.
If the filename equal (=) to the first class in it, then Visual Studio decides it is a simple C# file. If you have 2 classes and the first is not equal to the file name, then the solution icon changes and default editor is designer.
I don't know if you have same conditions in that link but opening your class in notepad, changing codes, replacing file then building the solution again may fix the problem.
I know that I can rename a namespace using Visual Studio 2010, but I need to remove part of a namespace.
namespace Xyz.Common.Utils { ... }
Renamed to
namespace Common.Utils { ... }
I need to drop the Xyz part, but don't see a way to use the VS refactoring tool to do this.
This is what I did a few times and you don't need any third-party tool:
Refactor the name in to something unique like: fjhfhchdbyegdrkoksodbc (if that's unique enough to you)Then do a global replace on fjhfhchdbyegdrkoksodbc. (including the dot) with an empty string.
There's no way to do that in pure Visual Studio, although there's an option when you select a word with the right button, then Refactor »» Rename in VS2010, this option requires you to select a symbol. In your case
namespace Xyz.Common.Utils { ... }
Xyz would be the symbol to refactor, but it cannot be renamed to an empty value.
Telerik JustCode can do the job instead:
http://www.telerik.com/products/justcode/features.aspx
There's also a Trial Version.
namespace Guilds
{
public class Wizard
{
public void Wear(IClothing clothing)
{
Console.WriteLine("Puts on the {Robe} and {WizardHat}".Fmt(clothing));
}
IClothing _clothes;
IWeapon _weapon; // <== I want my fields added at the bottom of the class!
}
}
I am aware that if you put your fields at the bottom, it will start adding subsequent ones to the bottom of the class as well. I would love to have this as the default behavior even for the first field.
This behavior is usually triggered when pressing Ctrl + . on top of an undeclared field.
Use Regionerate and create your own format template. it's free tool to use with visual studio.
Edit: You can also use CodeMaid because it seems that Regionerate and VS2012 do not work together (I have not tested that combination at all though. I have VS2010)
Edit Adding more to my previous reply. CodeMaid is really cool and you can specify the layout in configuration. Also in configuration, you can specify that file should be formatted on save. This way write your code in anyway you want and have it formatted when you press Ctrl+S! I am one happy user of CodeMaid. Also I am using Visual Studio 2013.
I have a namespace conflict between two referenced assemblies:
i.e., I'm referencing Foo.A.Foo and Foo.Bar, so when I say I want Foo.Bar.Control, VS is trying to find Foo.A.Foo.Bar.Control
I can twiddle the Designer.cs code by adding new global:Foo.Bar.Control(), but as soon as I change anything, VS switches back.
I know there's something about adding aliases directly to the reference, I've tried but haven't managed to find the right combination (inline alias, using alias, reference alias).
Help?
"extern alias" may be what you mean, but I'm not sure what the designer will do with it, unfortunately...
I'm not even sure that's what you're after though - that's normally for two types from different assemblies with the same name.
You can write namespace aliases with a using directive, e.g.
using FooControl = Foo.Bar.Control;
but again, the designer is going to rewrite your code...
OK, this isn't the answer, but it's what I found for a workaround:
namespace FooBar
{
class FooBarControlHack : Foo.Bar.Control { }
}
So I can do the following in the Designer.cs :
this.fooBarControl = new FooBar.FoorBarControlHack();