Search code examples
cssasp.netxamarinmonodevelop

Updating and Compiling CSS Files in Xamarin


I've recently started using Xamarin/MonoDevelop as an alternative to Microsoft Visual Studio and my first project was to create a website using ASP.NET with MVC pattern. This has been going well, and I don't mind the extra code work, but I'm having a rough time with the CSS.

For whatever reason, any CSS file only seems to compile once, ignoring any changes I write to the file. From my research, this because content files are cached for the build.

Is there a method in Xamorin's files, Microsoft's aspnet and web packages, or Newtonsoft's or Razor's library? If so, in which part of my solution do I call it?

Is there an add-on to Xamarin? How do I use it?

Do I have to modify a config file?


Solution

  • As pointed out in the comments, the issue was being caused by the browser cache not refreshing with changes to the build. The solution to this is to append a version to the end of the path name for the stylesheet. Since I am using cshtml, I decided to use this:

    <head>
        @{
            string version = "?v=2";
            string stylePathSite = "../../Content/Styles/SiteStyles.css" + 
                version;
            string stylePathNav = "../../Content/Styles/NavBarStyles.css" + 
                version;
        }
        <link rel="stylesheet" href="@stylePathSite"/>
        <link rel="stylesheet" href="@stylePathNav"/>
    </head>
    

    I can later write a controller to be update the version variable from my model. Hope any fellow newbies out there find this helpful.