Auto generated view.g.cs page keeps including old using statements? - wpf

I'm having a pretty difficult time with my resources within the view pages.
The auto generated view.g.cs page keeps including old using statements and I can't get it to stop. I have about 12 views and it will only do it on the first one, but then I delete that file completely and it then adds them to the next view. I've tried recreating the views and but the first one with the generated file still fails. I then set the build option to none, cleaned, rebuilt, and back to page, and it still happens!
I've tried deleting the actual generated files in the obj folder but they just get created again and the first view in my list then screws up again.
Any way around this? I think I've exhausted my options other then recreating the project but I'd prefer not to do this. Any other way to fix the generated files?
Cheers.

Try right-clicking on the XAML file and "Run custom tool".
This should generate the new, up-to-date .q.cs files.
EDIT:
Also, make sure that your own XAML and code-behind file is correct. The best way to do this is to perform a recursive search for the old namespace in all the files . in project directory (most appropiate part of it, for example: com.company.product.OldNameOfFeature - search for OldNameOfFeature). If there are any XAML or code files you'll need to fix them.
EDIT 2
This search should be done using external application outside Visual Studio, for example TotalCommander.
How to search in TotalCommander:

Figured out the issue, I had two warnings that said the new namespace was declared twice in the same file... builds successfully.
Cheers.

If you downgraded from .NET Core 6 to .NET Core 3.1, you need to fix your .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Remove the "<ImplicitUsings>enable</ImplicitUsings>" line.

Related

WPF Project Folder File Bloat

I work on my WPF project daily in Visual Studio 2022, and back-up my project folder in the evening. I can't help but notice the number of files in there just keeps getting greater (by hundreds every day), even when I'm not adding anything new to the project. It's causing back-up time, and the time it takes to transfer my files between workstations, to get longer and longer.
What could be generating these extra files and is there a way to minimize it?
I've had a look around the net for answers, but to no avail.
Thanks for all and any advice you can give me.
The best way to solve your problem is using the GitHub Repository.
Go to the Git Studio menu, select the create repository item in it, upload your Solution to the created Repository, commit the changes when you need it.
In addition to just backing up, this will allow you to easily and conveniently compare different versions.
If for some reason this is inconvenient for you, then pay attention to the ignore file in the Repository. All templated files and folders in this file do not require backup.
Here is a link to the ignore file from my Repository: https://github.com/EldHasp/CyberForumMyCycleRepos/blob/master/.gitignore
In the most minimal variant, all folders whose names begin with a dot, the bin, obj and packages folders do not require saving.
Try the following:
Try compiling in release mode instead of debug mode.
Try clearing the obj and bin folders
Turn off the automatic generation of xml.
Update:
My guess is that you are running your program in debug mode and your program is causing some files to grow.
There are the following methods to clean up the obj folder:
Right-click the project and select clean, then rebuild
Add the following code into the pre-build event, so that the obj folder will be cleaned up before each build, but this operation will delete the previous obj folder.
rmdir /s /q "$(ProjectDir)obj"

Check CopyLocal property of all references post/during build in multi project solution (Multi Xap)

I have a Silverlight solution that has multiple silverlight projects (Views) that all compile to their own .Xap file.
There is one "master" project that handles the dynamic downloading of the Xap files, which works pretty well.
But now I need to make sure that all the references are set to CopyLocal=false in all the View Projects. Only the "master" project can have CopyLocal=true.
This means that the Xap files generated by the Views stay rather small.
What I would like to do is check post or during the build process to see if any of the View projects have a reference with CopyLocal=true.
What would be a smart way of doing this? Using an external tool in the Post Build event? Or perhaps an addin for Visual Studio ? Or creating a macro in Visual Studio for this?
I have looked at using .extmap with assembly caching, but since you have to specify the assemblies in that, this does not solve my problem. I just need to know if there is a reference with the wrong setting and report that. Fixing it is not the question, that will still be done manually. It's just the notification I need.
Solution has 35 projects now, so dont want to check them all by hand every time.
I found a question similar to this one, but it lists msbuild as a possible solution. I would like to know if there is a way to do this using "code" (be it prebuilt in a tool/addin or otherwise)
I have chosen to go the Addin path. I created an addin that listens to : BuildEvents.OnBuildBegin
Whenever that event fires I create a list of all projects in the current solution. Doing a bit of recursive searching since there are also Solution folders that make life in DTE world a bit harder.
Then I loop through all the projects and cast them to a VSProject so I can loop through all the references.
Anytime I come accross a reference that is wrong, I create an ErrorTask where I set the Document property to the full solution path of the reference. To do this I Build the path for the project this reference is in, all the way up to the root of the solution.
The ErrorTask is then sent to an ErrorListHelper class I created, that handles the ErrorTasks and also performs navigation.
If I'm done with all the projects and I found any errors, I cancel the current build and show the Error List window, where my ErrorListHelper holds all the Reference Errors I created.
Whenever I want to navigate to the Reference in question, I activate the Solution Explorer window and get the root of it using an UIHierarchy.
Then I walk the path from the root on down, step by step, using the UIHierarchy to get to the UIHierarchyItems and expand them. Until I get to the deepest level (the reference) and I Select that.
Since I only need it for a certain solution and within that solution for certain projects (.Views.* and .ViewModels.*) I also have some checking for those in place during buildup of the Error List.
It works like a charm, already found 12 "wrong" References in 35 projects where I tought all were well.
I am using a different path now to do this. I have a base class that I can use to write unit tests that have access to the DTE2 object. This way I dont need an addin. This also works for Silverlight projects since the test class does not actually need access to the Silverlight projects, just being in the solution is enough to be able to iterate through the projects and check the references.

Using update-able FlowDocument XAML files as my WPF help system

I'm putting together a simple help system for my WPF app using XAML FlowDcouments (just .xaml files, no code-behind). I've simply added them to my project with Build Action = Resource, and I can load and display them as required.
Now, I'm trying to make it a bit more flexible, in that after the installation of the app, I want the user to be able to download additional (or newer versions of the existing) FlowDocument XAML help files. Given this, I'm now wondering where the best place to store these files is. A few questions/ideas:
Can I leave them as resource files, and overwrite or add new files as required? I can't find a example of how to add/edit resources at runtime on SO/Google. Is it even possible?
If not, is there a recommended location to store these files? They should be available to all users, so they can't go into the User's directory - they would have to go in the program directory. Does the program directory have write-access (I remember having issues with that before)?
Any other ideas?
Thanks.
The resource files are embedded into the executable and therefore you cannot change them.
As for a common place to put your downloaded help files, you cannot store them in "Program Files" since you would need admin privileges to write there.
I suggest you put them into SpecialFolder.CommonApplicationData (see http://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=vs.80).aspx), which is defined as "The directory that serves as a common repository for application-specific data that is used by all users."

Why does my DB project's .dbmdl file change even when I make no changes to the project?

I'm running into a small but weird annoyance that seems to be happening to other people, too (for example, check out the revision history of SEDE). I have a SQL Server 2008 database project in Visual Studio 2010 that works properly. When I go to commit/checkin to source control, I'm told that my DB project's .dbmdl file has changed, even when I've made no changes to the project!
I'm not sure if the changes are triggered by building my solution (which also includes an ASP.NET MVC application and a unit test project) or by simply opening the DB project, but this is getting kind of annoying and is creating clutter in source control.
Is it possible to stop these changes from occurring, or get rid of the .dbmdl file whatsoever?
If you delete the .dbml file, it is rebuilt without errors or warnings, so I think it's just a cache file for references, intellisense, etc. I'm going to exclude it from source control.
I believe Visual Studio serializes the dbmdl file every time the project is opened. The only possible work around would be to keep the project open.
See related question here. The .dbmdl file is unique per user (and some kind of cache, as said above) and so the right solution is indeed to exclude it from source control.

LocBaml include previous translations

Is there a way to combine a previous translation when extracting the csv file from an application?
Or any other tool that could do this job for me?
I can’t really see how could i use locbaml if i had to translate everything from scratch every time i add a new control in my application.
You might consider using something like WinMerge to merge the existing file with the old one.
You can try my open source addin http://easybaml.codeplex.com, which combines previous translations automatically. Right now it uses .resx instead of .csv, which can be changed if needed.

Resources