2022-03-30

GIT Bash listing all branches as new on every pull

 Problem: 

Whenever I did a "git pull" or "git fetch", it would list all branches as new, it seemed. 

Reason:

The reason was that we had subfolders in the path to the repo thet were written with either capital or small letters. Windows is not case sensitive, but git is. The subfolder somehow had been fetched with capital letters, but the standard was to have small characters.

Solution:

While in the root folder of your project...

cd .git/refs/remotes/origin/feature

ls

See that there is a folder with the wrong casing.

Do a:

rm OFFENDING_FOLDER -R

Navigate back down to project root folder.

Make sure that the branch you are on is using the path the way you want it.

git pull

It will now create the removed folder with the correct casing.


2018-01-05

Visual Studio 2017 - Go to Definition: Cannot navigate to the symbol undfer the caret.

Symptoms

The Go to Definition sometimes stops working, and I don't know why. The first symptom that this is happening is that the coloring of some class is unaltered (white) when it should be green.


Possibly related info

I am using VS 2017 Professional with ReSharper Ultimate.


Ways to fix it in order from least trouble afterwards to most


  • Clean solution
    • Close all files
    • Clean solution
    • Restart Visual Studio
    • Recompile all

    • This did not work for me.

  • Empty the symbol cache
    • Tools > Options > Debugging > Symbols > EmptySymbolCache
    • Open VS in admin mode

    • I have not tried this yet.

  • Delete the .vs folder
    • Close VS
    • Delete the .vs folder from your solution folder
    • Start VS
    • Recompile

    • I have not tried this yet.

  • Delete obj and bin folders
    • Close VS
    • Delete obj and bin folders from your project folder
    • Start VS
    • Recompile

    • I have not tried this yet

  • Delete the .user file from the project folder (may be hidden)
    • This will reset the customizations you've done to the IDE
    • The user file contains user preferences, such as debugging and deployment settings; used for saving and loading project preferences for a specific user.

    • I haven't tried this yet.

  • Run devenv.exe /resetuserdata
    • Devenv.exe may be found in...
      C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
    • This will reset many of your IDE customizations, including installed plugins.
    • ReSharper has to be repaired afterwards.

    • This worked for me.


Source:
https://stackoverflow.com/questions/33029127/go-to-definition-cannot-navigate-to-the-symbol-under-the-caret

2017-10-04

Webpack has been initialised using a configuration object that does not match the API schema.

On Windows, when running yarn (custom action "start") to start the dev server, on the step that starts the webpack-dev-server, I had the following error message:

$ webpack-dev-server --debug --hot --progress --colors
 10% building modules 2/2 modules 0 active
 Invalid configuration object. 
 Webpack has been initialised using a configuration object that does not match the API schema.
 ... 

This was not an easy one to understand, but it turned out to be very simple.

When I had CD-ed into the React app folder, I had typed the foldername with only lower case characters. The foldername was originally typed with a capital first letter. Webpack did not like that.

Solution:
cd ..
cd Folder
yarn start


2017-09-11

Adding nicer icons to the PageTree in EPiServer

I did some research about adding nicer icons for pages in the EPiServer Page Tree, and I came up with some nice resources.

What seems to be common for all approaches is that you must create css-classes that encapsule each icon to use. At the moment I don't see how to get around this without actually creating the classes.

You also need to create an InitializableModule which sets up the icons when the web is started. I have omitted that code here. Please read the example from the first example below (from blog.nansen.com), for that code.

This example is complete and shows how to use your own (or a third party lib) icons:
http://blog.nansen.com/2014/10/page-tree-icons-in-episerver-cms-75.html

This example shows how to create your own icons (as an image sprite) and use for the icons: https://jonika.nu/JonasBlogg/archives/347


Here's one that shows how to use the already included icons from EPiServer:
https://ericceric.ghost.io/use-episervers-content-icons-as-site-tree-icons/

In stead of creating and maintaining the list of Episerver icons yourself, as in the example above, you could go for the Jon D Jones nuget package: https://www.nuget.org/packages/JonDJones.IconPack/. This iconpack does not really contain any icons, just convenience constants that point to the built-in episerver icons (it seems so to me anyway).


I created a generic attribute, based on reflection, that plugs in the JonDJones icon pack (download from Nuget, as mentioned) into the first example I mentioned from the "nansenblog":

[AttributeUsage(AttributeTargets.Class)]
public class ContentIconAttribute : Attribute
{
    public ContentIconAttribute(Type type, string propertyName)
    {
        IconClass = GetStaticStringValueFromLib(type, propertyName);
    }

    private string GetStaticStringValueFromLib(Type libType, string name)
    {
        var fieldInfo = libType.GetField(name);
        var propInfo = libType.GetProperty(name);
        var value = (fieldInfo?.GetValue(null) ?? propInfo?.GetValue(null)) as string;
        return value;
    }

    /// 
    /// Css class to apply to the icon
    /// 
    public string IconClass { get; set; }
}

And here's how to use it:
using JonDJones.IconPack;

[ContentIcon(typeof(ObjectIcons), nameof(ObjectIcons.Start))]
public class StartPageModel : BasePage
{
    ...
}

2017-06-13

Always run Visual Studio as administrator

I am using Visual Studio a lot, and when I pin it to the task bar in Windows 10, right-clicking it will bring up a (popup) list of my last opened projects.

I need to run VS as Administrator, to be able to debug my web applications running on the local IIS.

So when I right-click the pinned VS-icon on the task bar, I can right-click on Visual Studio, then select "Run As Administrator", which is fine. The problem is that I cannot right-click on any of my previously opened solutions and run VS as admin while opening that solution.

On a shortcut (and probably also some exe-files) you will get the option to "always run as administrator". Problem is, this option does not appear when looking at the properties of the DevEnv.exe file, so you need to "fake" it by going into the compatibility settings.

In essense: What I want to do is basically to always open Visual Studio "As Administrator".

So here's how:

From link 1 below:
  1. Locate devenv.exe, by right-clicking the VS icon and selecting properties, then see the link in the shortcut.
  2. Right-click devenv.exe and choose Troubleshoot compatibility
  3. In the new window click at Troubleshoot Program
  4. Check The program requires additional permissions
  5. Click "Next" until you get to a button that says "Test the application". 
  6. Click the button and VS will be launched "As Administrator". 
  7. Switch back to the dialog, press "Next".
  8. Click the top option to save the preferences.

Sources:
  1. https://superuser.com/questions/465065/no-compatibility-tab-for-devenv-exe-vs-2010-and-vs-2012-on-windows-8
Related:


2017-04-19

Get time for given country

This code gets the first time zone for a country (meaning it probably won't work if your country has more than one), and calculates the date/time given the UTC date/time.

The method is an extension to the DateTime type, meaning you can use it by typing .AsLocalTimeForGivenCountryFromUtc(countryCode) after a variable or function returning that type. The countryCode parameter is a string, and must be a two-letter ISO 3166-1 country code.

You need to import John Skeets NodaTime library from NuGet.

Code:
using NodaTime.TimeZones;
using System;
using System.Linq;

namespace MyNameSpace
{

    public static class DateTimeExtension
    {

        public static DateTime AsLocalTimeForGivenCountryFromUtc(this DateTime utcDateTime, string countryCode)
        {
            //no matter what tz info is on the date, assume it is UTC
            var dte = new DateTime(utcDateTime.Year, utcDateTime.Month, utcDateTime.Day, utcDateTime.Hour, utcDateTime.Minute, utcDateTime.Second, DateTimeKind.Utc);
            var tzMapping = TzdbDateTimeZoneSource.Default.WindowsMapping.MapZones.FirstOrDefault(t => t.Territory == countryCode); //NodaTime
            var tz = TimeZoneInfo.FindSystemTimeZoneById(tzMapping.WindowsId);
            return TimeZoneInfo.ConvertTimeFromUtc(dte, tz);
        }
    }
}