从 g.cs 文件中删除旧的命名空间?
我以前的 WPF 应用程序项目中有一个名为“Controls”的子文件夹。它包含一个 WPF 用户控件。我决定将该用户控件移至我的“Views”文件夹。由于原始文件夹是空的,我决定将其从项目中删除。
由于用户控件和文件夹被删除,我收到编译错误,因为用户控件使用了 ProjectName.Folder 命名空间,现在没有任何内容引用它。 MainWindow.g.cs 是在 using 语句中引用 ProjectName.Controls
的内容。
我知道*.g.cs是VS生成的,无法编辑,因为它会被覆盖。我该怎么做才能不允许将该命名空间写入 g.cs 文件?我尝试清理我的解决方案/项目并重建,但没有任何效果。
I previously had a subfolder in my WPF application project called "Controls". It contained a WPF user control. I decided to move that user control to my "Views" folder. Since the original folder was empty, I decided to delete it from the project.
Because the user control and folder is removed I receive a compilation error because the user control used the ProjectName.Folder
namespace and now nothing references it. MainWindow.g.cs is what references ProjectName.Controls
in a using statement.
I know that *.g.cs are generated by VS and can't be edited because it will be overwritten. What do I do to not allow that namespace to be written to the g.cs file? I tried cleaning my solution/project and rebuilding but nothing has worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我的 Xaml 代码 (MainWindow.xaml) 中有一个对 Controls 命名空间的本地引用。我删除了引用,清理了项目并生成了成功的构建。
I had a local reference to the Controls namespace in my Xaml code (MainWindow.xaml). I removed the reference, cleaned the project and produced a successful build.
在您的用户控制文件中,
在 ClassName.xaml 中,您必须更改命名空间,如下所示
在您的 ClassName.xaml.cs 中,您必须更改命名空间,如下所示
在这两个文件中,您必须将 YourOldNamespace 替换为某个新的命名空间根据需要。
In your user control file,
In your ClassName.xaml, you must change the namespace as shown below
And in your ClassName.xaml.cs, you must change the namespace as shown below
In both the files, you must replace YourOldNamespace to some new namespace as needed.
我之前在项目中也遇到过 g.cs 文件的问题。由于它们是自动生成的,我倾向于手动删除文件并重建。
I have had problems with g.cs files in my projects before too. Since they are auto generated, I tend to just delete the file manually and rebuild.
也不要忘记,您必须检查单击受影响的 XAML 文件时的“构建操作”属性是否设置为 PAGE(而不是资源)。这对于了解何时使用复制粘贴从另一个项目复制 XAML 非常有用,可以节省时间。
Dont forget too, that you must check to see if the Build Action property when you click on the affected XAML file is set to PAGE (instead of resource). This is useful to know when you copy a XAML from another project using copy-paste to save time.
另请查看 App.xaml 和所有资源字典。无论出于何种原因,VS 2012 的文件替换/“整个解决方案”选项在 App.xaml 中找不到旧的命名空间引用,必须手动更改它。为我修好了。
Also look at App.xaml and all of your resource dictionaries. For whatever reason, VS 2012's replace in files / "Entire Solution" option didn't find the old namespace reference in App.xaml, had to manually change that. Fixed it for me.
不要忘记也更改您的 Generic.xaml 文件,
Don't forget to change your Generic.xaml file too,