Try our conversational search powered by Generative AI!

Upgrading an add-on with UI from CMS11 to CMS12 - help!!?

Vote:
 

I like to start out small, and work from there. So first I upgraded one add-on without UI and without any settings - it worked out great. Then I upgraded another add-on, still without any UI, and still no problems. 

The problems

The problems started when I tried to upgrade this addon with UI to CMS 12. It works on my machinetm, but when I deploy my site with the addon to Azure, it does not. Locally it works on an Alloy site (both .NET5 and .NET6 and my personal blog .NET6)

The current code: https://github.com/tomahg/Gulla.Episerver.SqlStudio
The NuGet: https://www.nuget.org/packages/Gulla.Episerver.SqlStudio/2.0.10

After a while, I reallized that I need this zip-file with the same name as my module, containing nothing but module.config

This is needed for the controller and view to be recognized, and for this part of the MenuProvider

  public IEnumerable<MenuItem> GetMenuItems()
  {
      var url = Paths.ToResource(GetType(), "container");

      return new MenuItem[]
      {
          new UrlMenuItem("SQL", MenuPaths.Global + "/cms/sqlstudio", url)
          {
              IsAvailable = context => _configurationService.Enabled()
          }
      };
  }

...and maybe also the embedded resouces.

If I do nothing special, the module folder will not be created. In order to fix this I added the file msbuild/CopyModule.targets

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
	<ItemGroup>
		<SourceScripts
		  Include="$(MSBuildThisFileDirectory)..\..\contentFiles\any\any\modules\_protected\**\*.*"/>
	</ItemGroup>

	<Target Name="CopyZipFiles" BeforeTargets="Build">
		<Copy
		  SourceFiles="@(SourceScripts)"
		  DestinationFolder="$(MSBuildProjectDirectory)\modules\_protected\%(RecursiveDir)"	/>
	</Target>
</Project>

After build, it will copy the zip-file (and a license file) to the module directory. This works fine locallly (on my machine).

When I build&deploy using Azure DevOps, and deploys my site (with the addon) to an Azure WebApp (.NET 6 running on Linux) the zip-file is NOT included. My yaml definition that does not include the zip file (but strangely includes zip files for other modules).

pool:
  vmImage: 'ubuntu-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
  displayName: 'use dotnet 6.0'
  inputs:
    packageType: 'sdk'
    version: '6.0.x'

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'
    feedsToUse: config
    nugetConfigPath: nuget.config

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: '**/*.csproj'
    arguments: '--configuration $(buildConfiguration)'

- task: DotNetCoreCLI@2
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

- task: PublishBuildArtifacts@1
  inputs:
    pathtoPublish: '$(Build.ArtifactStagingDirectory)' 

In order to include the zip-file in the deploy, when I deploy the site using the addon I am currently including this in my prosject file, as mentioned in my readme file.

<ItemGroup>
    <Content Include="modules\_protected\Gulla.Episerver.SqlStudio\Gulla.Episerver.SqlStudio.zip">
		<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
	</Content>
</ItemGroup>	

This should not be neccessary - but how can I fix it? Any suggestions?

I have read this blog post by Valdis, I have looked at the Geta notfoundhandler aand Geta sitemaps - but I cannot understand what I'm doing wrong.

#280792
Edited, May 23, 2022 19:39
Vote:
 

This is the standard copyzipfiles.target in our modules.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
    <ItemGroup>
        <SourceScripts Include="$(MSBuildThisFileDirectory)..\..\contentFiles\any\any\modules\_protected\**\*.zip"/>
    </ItemGroup>

    <Target Name="CopyZipFiles" BeforeTargets="Build">
        <Copy
            SourceFiles="@(SourceScripts)"
            DestinationFolder="$(MSBuildProjectDirectory)\modules\_protected\%(RecursiveDir)"
        />
    </Target>
</Project>
#280831
May 24, 2022 14:17
Vote:
 

If you restructure your project as a Razor Class Library, then you don't need to worry about build scripts for creating zip files and defining where files go.  The compiled DLL is all that is needed and that packages up so easily.

Feel free to look at the solution for my package: https://github.com/GeekInTheNorth/Stott.Optimizely.RobotsHandler

#280928
May 26, 2022 12:44
Vote:
 

Thanks Mark Hall, but that's almost exactly what I had.

I changed my target-file to exactly what you suggested, and it still only works locally. The file does not get added to the published artifact when I build using Azure Devops.

#281017
Edited, May 28, 2022 11:53
Vote:
 

Thanks Mark Stott!

My project were already a Razor Class Library, and the contents of my zip file weren't used. I used it to generate the URL to my module, and I was under the misconception that it was neccessary to get the correct routes to embedded views and recourses. Even if I tried to remove it earlier, but did not succeed. It turned out I did not need it at all!

Now I were able to delete and simplify some code - and get rid of all the copying magic.

Thanks a lot!

#281018
Edited, May 28, 2022 12:20
Mark Stott - May 29, 2022 19:01
Glad to be of service :)
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.