How to install component and route plugin in one package? - joomla

I have created custom component and a route plugin for Joomla 1.5 to to provide SEO URLs for my component and also articles and categories which are not menu tied. Now I have to install my component and route plugin separately. Is there a way to install both in one package please?
Thank you in advance! Vojtech

There is a easier method.
What is a package?
A package is a extension that is used to install multiple extensions in one go.
How do I create a package?
A package extension is created by zipping all zip files of the extensions together with a xml manifest file. For example if you have a package composed by:
component helloworld
module helloworld
library helloworld
system plugin helloworld
template helloworld
The package should have the following tree in your zipfile:
-- pkg_helloworld.xml
-- packages <dir>
|-- com_helloworld.zip
|-- mod_helloworld.zip
|-- lib_helloworld.zip
|-- plg_sys_helloworld.zip
|-- tpl_helloworld.zip
The pkg_helloworld.xml could have the following contents:
<?xml version="1.0" encoding="UTF-8" ?>
<extension type="package" version="1.6">
<name>Hello World Package</name>
<author>Hello World Package Team</author>
<creationDate>May 2012</creationDate>
<packagename>helloworld</packagename>
<version>1.0.0</version>
<url>http://www.yoururl.com/</url>
<packager>Hello World Package Team</packager>
<packagerurl>http://www.yoururl.com/</packagerurl>
<description>Example package to combine multiple extensions</description>
<update>http://www.updateurl.com/update</update>
<files folder="packages">
<file type="component" id="helloworld" >com_helloworld.zip</file>
<file type="module" id="helloworld" client="site">mod_helloworld.zip</file>
<file type="library" id="helloworld">lib_helloworld.zip</file>
<file type="plugin" id="helloworld" group="system">plg_sys_helloworld.zip</file>
<file type="template" id="helloworld" client="site">tpl_helloworld.zip</file>
</files>
</extension>

When any extension installed Joomla triggers an event 'com_yourcomponent_install()' to your install file, which you have mentioned in xml file.
write a function com_yourcomponent_install in which get the path of plugin folder and install it
$installer = new JInstaller();
// Install the packages
$installer->install($pluginPath);
For example
in you xml file install.mycomponent.php
and in install.mycomponent.php there should be a function com_mycomponent_install()
this function will contain the code as
$installer = new JInstaller();
// Install the packages
$installer->install($pluginPath);

Related

Create nuget containing shared project properties - automatic references

We would like to create a nuget that contains an msbuild properties (.props) file. We do this by creating a nuspec which as the following MIL (most important line) :
<files>
<file src="SharedProperties.props" target="build\SharedProperties.props" />
</files>
How can we change our .nuspec definition so that a project (.csproj) that references this nuget will automatically include the property file ("like" line 3 in this snippet):
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Shared\SharedProperties.props" />
(Is this even possible ?)
That is a feature of the nuget package design. And nuget has the automatic import targets mechanism. See this document.
The tip is that you should name the targets or props file to <package_id>.props or targets and then pack the file into build folder. That is all.
For an example, I created a lib project and then use this nuspec file to pack:
<?xml version="1.0" encoding="utf-8"?>
<package >
<metadata>
<id>test_A</id>
<version>1.0.0</version>
<title>me</title>
<authors>me</authors>
......
</metadata>
<files>
<file src="test_A.props" target="build" />
</files>
</package>
If my package is called test_A.1.0.0.nupkg, the file should be named as test_A.props file.
Then, when you install the nuget package into a new project, you can check the <new project>.csproj file, the props file is added automatically during the nuget installation.
If you use PackageReference nuget management format to install the nuget package, the file is added under obj\xxx.csproj.nuget.g.props or obj\xxx.csproj.nuget.g.targets file:
For new-sdk project, that also work. If you create a new-sdk class library project, you could use this into csproj file to pack it:
<None Include="<packages_id>.props" Pack="true" PackagePath="build">
When you finish it, install the new package into new-sdk main project, you will find that the props file has imported automatically under obj\xxx.csproj.nuget.g.props file.
According to the documentation the ".props" file should be automatically added to the beginning of a .csproj as an import (a .targets file should go to the end). However, for the new sdk-style projects this doesn't seem to work?

Prevent content files to be added on Nuget restore

We have some executables which we need to create our setups. So we have packed
the external dependencies which are some .exe files into a nuget package. But on NuGet restore they are added to project root.
How can we achieve this ?
Have searched around but haven't found any solution so far.
Since we use nuspec file, this is what i have it as:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>VCRedistributable</id>
<version>$version$</version>
<title>VCRedistributable</title>
<authors>--</authors>
<owners>--</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>InstallVCRedistributable assemblies</description>
<contentFiles>
<files include="**" exclude="**" buildAction="None" copyToOutput="false"
/>
</contentFiles>
</metadata>
<files>
<file src="VC\x86\*.*" target="content\x86" />
<file src="VC\x64\*.*" target="content\x64" />
</files>
Any ideas ?
Prevent content files to be added on Nuget restore
You should target to the tools folder instead of content folder.
So, your .nupsec file should be:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>VCRedistributable</id>
<version>$version$</version>
<title>VCRedistributable</title>
<authors>--</authors>
<owners>--</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>InstallVCRedistributable assemblies</description>
</metadata>
<files>
<file src="VC\x86\*.*" target="tools\x86" />
<file src="VC\x64\*.*" target="tools\x64" />
</files>
</package>
That because the content directory is a convention-based working directory, which contents are copied to the project root:
Convention-based working directory:
Besides, if you nuget package just include external some .exe files, you do not have to add the contentFiles label, this label is used for the content file for packagereference.
<contentFiles>
<files include="**" exclude="**" buildAction="None" copyToOutput="false"
/>
</contentFiles>
If you are interested in, you can check this document for some more details.
Update:
Is it good convention to create our own folder structure other than
NuGet defined since based on the tools folder description from above
it seems they will be accessible via Package Manager Console.
Of course, you can use your own folder structure other than NuGet defined. But you need to notice that there will be a limit to do this. You can NOT just include your own folder structure, you need also need add a NuGet defined folder structure in your .nuspec, otherwise, nuget will install failed with the error like:
Could not install package 'MyCustomPackage 1.0.0'. You are trying to
install this package into a project that targets
'.NETFramework,Version=v4.6.1', but the package does not contain any
assembly references or content files that are compatible with that
framework.
Because nuget did not detect that you added assembly references or content files to the project.
Hope this helps.

Automatically add project dependency metadata to manually created nuspec file

When I nuget pack a web project I want to specify custom unpack locations for content and maintain project dependency metadata.
Given the following manually created example nuspec file:
<?xml version="1.0"?>
<package>
<metadata>
<id>Web.MyApp</id>
<version>1.0</version>
<title>Web.MyApp</title>
<authors>Chris</authors>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Nuget package containing files for Web.MyApp</description>
<releaseNotes>release notes</releaseNotes>
<copyright>Copyright Chris 2017</copyright>
<tags />
<dependencies />
</metadata>
<files>
<file src="bin\**\*.*" target="bin" />
<file src="views\**\*.*" target="views" />
<file src="content\" target="content" />
<file src="scripts\" target="scripts" />
<file src="Global.asax" target="" />
<file src="*.config" target="" />
</files>
</package>
This allows me to specify custom unpack locations for bin, content, sprint folders etc but I want the project dependency metadata to be automatically maintained. I don't want to edit the nupsec each time a new dependency is referenced.
As an attempt to resolve this problem I tried to nuget pack the csproj file instead of the nuspec. This maintained the dependency metadata however it made specifying content unpack locations much trickier. I can do the following:
<Content Include="Content\dist\images\brand-logo.svg">
<Pack>true</Pack>
<PackagePath>Content\Content\dist</PackagePath>
</Content>
But I couldn't find an elegant solution for the bin folder. I just feel like I'm doing something fundamentally wrong.
So my question is, how can I automatically maintain project dependency metadata when creating a nuget package from a manually created nuspec file?
The pack command I am using:
..\tools\nuget\nuget.exe pack $project + ".nuspec" -IncludeReferencedProjects -
Properties Configuration=Release -Verbosity quiet -NonInteractive -
OutputDirectory "$packagedirectory" -Version $buildVersion -Symbols
Automatically add project dependency metadata to manually created nuspec file
If I understand you correct, I am afraid you have already automatically add project dependency metadata to manually created .nuspec file. You just need to rebuild the project and re-pack the .nuspec file.
When you include the referenced files with wildcard, it will contain the new added project references:
<file src="bin\**\*.*" target="bin" />
Add a new project reference to the project, then re-build the project, the dll file of referenced project will be copied to the \bin folder, So we just need to re-pack the .nuspec file, the referenced project metadata will included in the new created package.
For example, add a Atest reference project to Web.MyApp project, then rebuild the project and re-pack the .nuspec file:
If I misunderstand you, please let me know for free.

Joomla 3: How to uninstall module from a package?

In my package, I have a module and a plugin. When I uninstall a package from the Extension Manager, the plugin gets uninstalled but the module remains there. Also the package entry gets removed from the Extension Manager. Then I have to manually uninstall the module. I get the following messages:
Warning
Attempting to uninstall unknown extension from package.
This extension may have already been removed earlier.
Message
Uninstalling package was successful.
How do I ensure the module gets uninstalled when I uninstall the package?
UPDATE:
My package manifest:
<?xml version="1.0" encoding="UTF-8" ?>
<extension type="package" version="3.0">
<name>RR Test One Package</name>
<author>John Doe</author>
<creationDate>November 2013</creationDate>
<packagename>rr_test_one_package</packagename>
<version>1.0</version>
<packager>John Doe</packager>
<description>Lorem ipsum dolor sit amet.</description>
<files folder="packages">
<file type="module" id="rr_test_one" client="site">mod_rr_test_one.zip</file>
<file type="plugin" id="rr_test_one" group="content">plg_content_rr_test_one.zip</file>
</files>
</extension>
I have script.php inside the plugin and module folders to make some updates to the database entries. The plugin uninstalls without the uninstall function when I uninstall the package. It's just not uninstalling the module. Do I need to have another script.php in the packages folder along with the package manifest and have the uninstall function in the script.php?
It was the id in the <file> tag of the module type that was giving out the warning. I added mod_ in the id. Below is what I did and this resolved the issue.
<files folder="packages">
<file type="module" id="mod_rr_test_one" client="site">mod_rr_test_one.zip</file>
<file type="plugin" id="rr_test_one" group="content">plg_content_rr_test_one.zip</file>
</files>

NuGet exclude content project references

I want to create a NuGet package with some files in content, I want these files to be added to the project but not referenced by the project, hence they are not compiled. How would I go about this?
Thanks
Edit your nuspec file, putting in the references to your files like so:
<?xml version="1.0"?>
<package>
<metadata>
...
</metadata>
<files>
...
<file src="MyFirstContentFile.txt" target="content" />
<file src="MySecondContentFile.cs" target="content" />
...
</files>
</package>
The target="content" bit is what does the magic of copying the files into your project.
Now, if the files you are importing into the project are code files (e.g. .cs files), and you don't want them to be compiled, you need to set the build action of those files. To do this you need to do some work on the install.ps1 file (create one if you have not yet got one, and don't forget to reference the file in your files section with target="tools"):
param($installPath, $toolsPath, $package, $project)
$file1 = $project.ProjectItems.Item("MyFirstContentFile.txt")
$file2 = $project.ProjectItems.Item("MySecondContentFile.cs")
# set 'BuildAction' to 'Content'
$copyToOutput1 = $file1.Properties.Item("BuildAction")
$copyToOutput1.Value = 2
$copyToOutput2 = $file2.Properties.Item("BuildAction")
$copyToOutput2.Value = 2
See the following link for possible values of the BuildAction enum.
http://msdn.microsoft.com/en-us/library/aa983962(VS.71).aspx

Resources