Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Gianni Declercq 7 posts 77 karma points
    Jun 17, 2022 @ 22:10
    Gianni Declercq
    0

    Umbraco 10 static assets

    Hi,

    Upgrading from Umbraco 9 I get the following error during build: Conflicting assets with the same target path umbraco/assets/css/..

    I read that the folder wwwroot/umbraco is no longer needed in umbraco 10?

    The problem is that we have a plugin that uses some assets from that folder and now that it is gone it no longer works..

    I noticed when running dotnet publish it does copy this folder to the output. How do I copy this folder again during build to the wwwroot directory?

  • Kevin Jump 2146 posts 13582 karma points MVP 6x c-trib
    Jun 18, 2022 @ 08:47
    Kevin Jump
    1

    Hi Gianni,

    Yeah when you are developing a site those files now come from your local .nuget cache folder but aspnet core uses FileProviders to make it look like they are coming from the site.

    Via Javascript

    if your plugin is using these files from JavaScript then in theory accessing them should still work because the browser will still think they are in the same location.

    e.g - this code uses the assetService to load the jsDiff library (and works in v10)

    var jsdiff = 'lib/jsdiff/diff.js';
    
    assetsService.loadJs(jsdiff, $scope).then(function () {
        calcDiffs();
    });
    

    but do check you have the right URL as some files have also changed for example the jsdiff library path has changed from lib/jsdiff/diff.min.js to lib/jsdiff/diff.js subtle but will cause you problems.

    Via c# code

    If your plugin is accessing files in the folder from c# then you need to switch over to using the FileProvider to locate the files (as opposed to System.IO.File libraries - because the files aren't really there but the file provider makes it look like they are.

    If you use the FileProvider from IWebHostEnvironment.

    e.g (also note i haven't tested this code. but its something like this)

    var fileProvider = webHostEnvironment.WebRootFileProvider;
    var fileInfo = fileProvider.GetFileInfo("/umbraco/libs/jsdiff/diff.js");
    if (fileInfo != null)
    {
        var path = fileInfo.PhysicalPath;
        var fileContents = System.IO.File.ReadAllText(path);
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft