Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable dnn manifest tokens #16

Closed
1 task done
dazinator opened this issue Jul 9, 2015 · 6 comments
Closed
1 task done

Enable dnn manifest tokens #16

dazinator opened this issue Jul 9, 2015 · 6 comments

Comments

@dazinator
Copy link
Owner

Rather than the developer having to explicitly replace some values (in square brackets) in the DNN manifest file, I could automatically set them using properties of the project. For example, rather than the following manifest file:

<package name="[YourPackageName]" type="Module" version="0.0.0">
      <friendlyName>[FriendlyPackageName]</friendlyName>
      <description></description>

It could instead contain variables that I will automatically substitute with appropriate values:

<package name="$projectName$" type="Module" version="$manifestVersionNumer$">
      <friendlyName>$assemblyTitle$</friendlyName>
      <description>$assemblyDescription$</description>

These values will come from the corresponding project properties

image

One important thing to note will be that when you use a variable in the manifest for the version number (like below), then by default it will be set according to an MsBuild property named $(manifestVersionNumber) which by default, will be set from the AssemblyInfoVersion (Major.Minor.Build). You could optionally override this variable with your own version number - i.e perhaps a version number based on the Team City build counter etc.

<package name="$projectName$" type="Module" version="$manifestVersionNumer$">
@dazinator
Copy link
Owner Author

NuGet can actually replace some parameters in the manifest file when it's installed, based upon some project properties.

I'm going to experiment with this to see if the some values in the manifest can be set with sensible default values at install time.

dazinator added a commit that referenced this issue Feb 13, 2016
…that nuget will replace when the manifest file is installed to the project by NuGet.
@david-poindexter
Copy link
Contributor

That would be cool!

dazinator added a commit that referenced this issue Feb 13, 2016
dazinator added a commit that referenced this issue Feb 13, 2016
dazinator added a commit that referenced this issue Feb 13, 2016
dazinator added a commit that referenced this issue Feb 13, 2016
@dazinator
Copy link
Owner Author

I have implemented this feature "in part" by using NuGet to replace tokens in the manifest with project values when the manifest is added, but that's not the full feature I was going for, as if you then change your project or assembly name, this won't update anything in the manifest, you would have to remember to manually update your manifest as the tokens are only replaced once at package install time. I'm happy to leave things like this for now, if there is more demand for this feature in future, can come back to it at that point.

@david-poindexter
Copy link
Contributor

I think this is a great start!

@mtrutledge
Copy link

I do this in my projects with a MSBUILD trick. Here is what I setup in my project files after I install DNNPackager:

<UsingTask TaskName="ReplaceFileText" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> <ParameterGroup> <InputFilename ParameterType="System.String" Required="true" /> <OutputFilename ParameterType="System.String" Required="true" /> <MatchExpression ParameterType="System.String" Required="true" /> <ReplacementText ParameterType="System.String" Required="true" /> </ParameterGroup> <Task> <Reference Include="System.Core" /> <Using Namespace="System" /> <Using Namespace="System.IO" /> <Using Namespace="System.Text.RegularExpressions" /> <Code Type="Fragment" Language="cs"><![CDATA[ File.WriteAllText( OutputFilename, Regex.Replace(File.ReadAllText(InputFilename), MatchExpression, ReplacementText) ); ]]></Code> </Task> </UsingTask> <PropertyGroup> <BUILD_NUMBER Condition="'$(BUILD_NUMBER)' == ''">4.2.4.0</BUILD_NUMBER> </PropertyGroup> <Target Name="BeforeBuild" BeforeTargets="DnnPackagerPreBuild"> <Message Text="Backup Manifest File" Importance="high" /> <Copy SourceFiles="$(ProjectDir)manifest.dnn" DestinationFiles="$(ProjectDir)manifest.orig" /> <Message Text="Set Manfiest File Version to: $(BUILD_NUMBER)" Importance="high" /> <ReplaceFileText InputFilename="$(ProjectDir)manifest.dnn" OutputFilename="$(ProjectDir)manifest.dnn" MatchExpression="\$version\$" ReplacementText="$(BUILD_NUMBER)" /> </Target> <Target Name="AfterBuild" DependsOnTargets="DnnPackagerBuildInstallZip"> <Message Text="Delete Backup Manifest File" Importance="high" /> <Copy SourceFiles="$(ProjectDir)manifest.orig" DestinationFiles="$(ProjectDir)manifest.dnn" /> <Delete Files="$(ProjectDir)manifest.orig" /> </Target>

The BUILD_NUMBER field defaults to a hard coded version for the manifest file, but if built through Team City it will be the build number field. Maybe this will help you with making it more generic and integrate into your package.

@dazinator
Copy link
Owner Author

dazinator commented Jun 7, 2016

Wow thank you for sharing this. It's pretty cool that you found a way to do this in way that integrates nicely with DnnPackager. I would love to see DnnPackager have this token replacement functionality in the future, with some more tokens sourced most likely from assembly info file. As always though, it's just about finding the time to work on it! ;)
P.S if you ever find yourself with some spare time to contribute further around this, please feel free to start a PR! ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants