[Resolved] Views not updating on code change. Also...
# help-with-umbraco
d
Hey, I'm new to Umbraco. Using v12, simple website using Atomic Starter Kit. Whenever I make a simple change (let's say in Header.cshtml, making a link bold), in VS Code changes don't show in view when I refresh. Also, when doing a
dotnet build
command, all changes in cshtml from starter kits get undone (like a revert to default) How do I customize the cshtml code, based on a starter kit? Solutions tried 1. Disabling Cache in Chrome -> Network -> Disable Cache 2. Changed values for this one, with no effect
Copy code
<!-- Remove RazorCompileOnBuild and RazorCompileOnPublish when not using ModelsMode InMemoryAuto -->
    <RazorCompileOnBuild>true</RazorCompileOnBuild>
3. Switched this between on off with no effect (I think it words on js and css anyway, not cshtml)
Copy code
"RuntimeMinification": {
        "UseInMemoryCache": false,
        "CacheBuster": "Timestamp"
      }
I got the change to appear from time to time, so I guess it's something with time based caching in DB, and don't know how to disable it
s
Hi, this is probably because the starter kit is made to copy in all its files on build. Try removing the underlying nuget package. This should not remove anything in the database, and if it removes your files you can revert those via git.
d
Hey, thanks for the reply. Not working unfortunately, because the views use the namespace in the package
Copy code
/Views/_ViewImports.cshtml(6,7): error CS0246: The type or namespace name 'Atomic' could not be found (are you missing a using directive or an assembly reference?)
Seems to be an issue with Atomic Starter Kit. Created an issue on their website https://github.com/umbraco/The-Starter-Kit/issues/126 Tried installing a fresh instance of Umbraco, this time with the Clean Starter Kit. All works perfectly, as expected with it, changes reflect instantly, and views are not reset to default, on build
s
that's not the atomic starter kit repo 😅 Maybe these people can help https://atomictoolkit.com/contributors/
d
I asked them on their github 🙂
m
You can use a build targets addition to csproj to copy a local version of the file you want to change after build/publish has happened.. here's an example.. Is it a bit of a last resort though as it means you have to keep an eye on that file changing in subsequent package updates.
Copy code
xml
    
  <Target Name="Custom_AfterBuild" AfterTargets="Build" Condition="Exists('$(Projectdir)..\ExternalDependencies\Our.Umbraco.DocTypeGridEditor.dll')">
    <Exec Command="echo Custom_Replacing DTGE dlls" />
    <Exec Command="echo $(Projectdir)..\ExternalDependencies\Our.Umbraco.DocTypeGridEditor.dll - $(Projectdir)bin\$(Configuration)\net5.0\Our.Umbraco.DocTypeGridEditor.dll" />
    <Copy SourceFiles="$(Projectdir)..\ExternalDependencies\Our.Umbraco.DocTypeGridEditor.dll" DestinationFiles="$(Projectdir)bin\$(Configuration)\net5.0\Our.Umbraco.DocTypeGridEditor.dll" />
  </Target>
    
  <Target Name="Custom_Override Copy to Local nuget" AfterTargets="_CopyFilesMarkedCopyLocal" Condition="Exists('$(Projectdir)..\ExternalDependencies\Our.Umbraco.DocTypeGridEditor.dll')">
    <Exec Command="echo Custom_Override Copy to Local nuget" />
    <Exec Command="echo $(Projectdir)..\ExternalDependencies\Our.Umbraco.DocTypeGridEditor.dll - $(PublishDir)Our.Umbraco.DocTypeGridEditor.dll" />
    <Copy SourceFiles="$(Projectdir)..\ExternalDependencies\Our.Umbraco.DocTypeGridEditor.dll" DestinationFiles="$(PublishDir)Our.Umbraco.DocTypeGridEditor.dll" />
  </Target>
Or you can get a little more verbose and have an entire directory structure recursively replace files. Here is starting at app_plugins for instance
Copy code
xml
    <PropertyGroup>
        <CstAppPluginOverrideFilesPath>$(MSBuildThisFileDirectory)..\ExternalDependencies\App_Plugins\**\*.*</CstAppPluginOverrideFilesPath>
    </PropertyGroup>

    <Target Name="Cst_AfterBuild" AfterTargets="Build" Condition="Exists('$(Projectdir)..\ExternalDependencies\App_Plugins')">
        <!-- set at the same filepath in ..\ExternalDependencies\App_Plugins to copy over -->
        <!-- for running locally  -->
        <ItemGroup>
            <CstAppPluginOverrideFiles Include="$(CstAppPluginOverrideFilesPath)" />
        </ItemGroup>
        <Message Text="Copying Cst App_Plugin Overrides: $(CstAppPluginOverrideFilesPath) - #@(CstAppPluginOverrideFiles->Count()) files to $(ProjectDir)App_Plugins" Importance="high" />
        <Copy SourceFiles="@(CstAppPluginOverrideFiles)" DestinationFiles="@(CstAppPluginOverrideFiles->'$(ProjectDir)\App_Plugins\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />        
    </Target>
    <Target Name="Cst_AfterCopyFilesMarkedCopyLocal" AfterTargets="_CopyFilesMarkedCopyLocal" Condition="Exists('$(Projectdir)..\ExternalDependencies\App_Plugins')">
        <!-- set at the same filepath in ..\ExternalDependencies\App_Plugins to copy over -->
        <!-- for published  -->
        <ItemGroup>
            <CstAppPluginOverrideFiles Include="$(CstAppPluginOverrideFilesPath)" />
        </ItemGroup>
        <Message Text="Copying Cst App_Plugin Overrides: $(CstAppPluginOverrideFilesPath) - #@(CstAppPluginOverrideFiles->Count()) files to $(publishDir)App_Plugins" Importance="high" />
        <Copy SourceFiles="@(CstAppPluginOverrideFiles)" DestinationFiles="@(CstAppPluginOverrideFiles->'$(PublishDir)\App_Plugins\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" />
    </Target>
d
Thank you, nice idea
ideally, I hope there's a way to disable this behavior, at least in development phase
I don't have any of these issues with a different starter kit (clean starter kit)
so I hope creators of that kit will have a feature flag way of disabling cache or recopying files
so I don't have to do hacks or do more elaborate copy mechanisms
still, nice idea, as you said I'd only use it as last resort
m
I think you'll find that the immutable files delivered by nuget packages is the standard now (promoting contribution to the package to extend??).. just as you'd find with most packages that deliver files to the app_plugins folder, even more so with razor class libraries now for templates too. Some packages going the rcl approach then allow for local file overrides.. https://github.com/ffwagency/atomic-toolkit/blob/v12/master/src/Atomic.StarterKit/buildTransitive/Atomic.StarterKit.targets as you can see it recursively copies views from the package on every build Looks like the package developer really wants those files to be as they intended as they have set
OverwriteReadOnlyFiles="true"
🙂
d
thanks a lot, great find! It makes sense now
16 Views