Display project version in ASP.NET Core 1.0.0 web application - version

None of what used to work in RC.x helps anymore.
I have tried these:
PlatformServices.Default.Application.ApplicationVersion;
typeof(Controller).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
Assembly.GetEntryAssembly().GetName().Version.ToString();
They all return 1.0.0.0 instead of 1.0.0-9 which should be after execution of the dotnet publish --version-suffix 9 having this in project.json: "version": "1.0.0-*"
Basically they give me "File version" from the attached picture instead of "Product version" which dotnet publish actually seems to change.

For version 1.x:
Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
For version 2.0.0 this attribute contains something ugly:
2.0.0 built by: dlab-DDVSOWINAGE041 so use this one:
typeof(RuntimeEnvironment).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;

I would do it like this on ASP.NET Core 2.0+
var assemblyVersion = typeof(Startup).Assembly.GetName().Version.ToString();

In .Net Core 3.1 I show the version directly in my View using:
#GetType().Assembly.GetName().Version.ToString()
This shows the Assembly Version you have in your csproj file:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
<FileVersion>2.2.2.2</FileVersion>
<Version>4.0.0-NetCoreRC</Version>
</PropertyGroup>
If you want to display the "other" FileVersion or "Informational" Version properties in the View add using System.Reflection:
using System.Reflection;
.... bunch of html and stuff
<footer class="main-footer">
<div class="float-right hidden-xs">
<b>Assembly Version</b> #(Assembly.GetEntryAssembly().GetName().Version)
<b>File Version</b> #(Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>().Version)
<b>Info Version</b> #(Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion)
</div>
</footer>
Note that after adding the System.Reflection the original #GetType().Assembly.GetName().Version.ToString() line returns 0.0.0.0 and you need to use the #Assembly.GetEntryAssembly().GetName().Version
There's a blog post here
Edit: Make sure to follow proper naming conventions for the Version strings. In general, they need to lead with a number. If you don't, your app will build but when you try to use NuGet to add or restore packages you'll get an error like 'anythingGoesVersion' is not a valid version string. Or a more cryptic error: Missing required property 'Name'. Input files: C:\Users....csproj.'
more here:

This work for me too:
#Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.Application.ApplicationVersion
It works with csproj file - either <Version>1.2.3.4, or <VersionPrefix>1.2.3</VersionPrefix>. However the <VersionSuffix> isn't recoganized as this doc says.

The answer by Michael G should have been the accepted one since it works as expected. Just citing the answer by Michael G above.
var version = GetType().Assembly.GetName().Version.ToString();
works fine. It gets the Package version set in the Package tab of project properties.
As an addition, if we need to get the Description we set in the same tab, this code would work. (core 3.1)
string desc = GetType().Assembly.GetCustomAttribute<AssemblyDescriptionAttribute>().Description;
Just in case someone needs this.
Happy coding !!!

Related

OWL API V5 read ontology from local file

in the current documentation example at the link:
https://github.com/owlcs/owlapi/blob/version5/contract/src/test/java/org/semanticweb/owlapi/examples/Examples.java
There is no example of how to load an ontology from a local file. There is only a way to load it from a string.
In the past when i used owl-api version 3
the following code worked perfectly:
OWLOntologyManager manager =OWLManager.createOWLOntologyManager();
File file = new File (path);
OWLOntology ont = manager.loadOntologyFromOntologyDocument(IRI.create(file));
however, in this version, the last line of the previous code:
manager.loadOntologyFromOntologyDocument(IRI.create(file));
returns this error:
Exception in thread "main" java.lang.NoSuchMethodError:
org.semanticweb.owlapi.util.SAXParsers.initParserWithOWLAPIStandards(Lorg/xml/sax/ext/DeclHandler;)Ljavax/xml/parsers/SAXParser;
at
org.semanticweb.owlapi.rdf.rdfxml.parser.RDFParser.parse(RDFParser.java:148)
at org.semanticweb.owlapi.rdf.rdfxml.parser.RDFXMLParser.parse(RDFXMLParser.java:62)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyFactoryImpl.loadOWLOntology(OWLOntologyFactoryImpl.java:173)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.load(OWLOntologyManagerImpl.java:954)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntology(OWLOntologyManagerImpl.java:918)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyManagerImpl.loadOntologyFromOntologyDocument(OWLOntologyManagerImpl.java:859)
at glass.main.ontology_Test_main2.readOntology(ontology_Test_main2.java:49)
at glass.main.ontology_Test_main2.main(ontology_Test_main2.java:38)
Kindly note the attachment, a small test java project, link:
dropbox.com/s/3787a3gsk2bwc26/test.tar.gz?dl=0
Kindly what am i doing wrong, i m sure that this code
Kindly would you please provide the correct way to do it, and add it to the tutorial example in the link https://github.com/owlcs/owlapi/blob/version5/contract/src/test/java/org/semanticweb/owlapi/examples/Examples.java
Thanks very much for your time.
Sincere regards
You are very near to the solution:
final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
final OWLOntology ontology = manager.loadOntologyFromOntologyDocument(new File("/home/galigator/myLocalDir/aura.owl"));
Just use new File instead of IRI.create
The reason of the problem was:
The previous versions that i was using:
I was using Hermit version 1.3.8.500 and OWL-API previous version 5.0.5 got modified it seems.
Solution: use the newer versions Hermit 1.3.8.510 and OWL-API 5.1.0.
I posted this answer in case someone else is using the previous version and got affected.
Sincere regards.

R - error installing caret package

> Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()),
> versionCheck = vI[[j]]) : namespace ‘pbkrtest’ 0.4-2 is being
> loaded, but >= 0.4.4 is required
> Error: package or namespace load
> failed for ‘caret’
Caret was working fine until I tried to load Rcpp and it messed everything up.
I searched the answers for a similar problem with caret but the solutions posted did not seem to work on mine. I followed:
install.packages("caret", dependencies = TRUE)
But it did not work.
I would suggest you to check the R version. I updated the version to 3.5.1 and it works perfectly :)
Mac only – use updateR
Similar to installr, updateR is the package to help updating R on Mac OS.
The R code you will need are the following 5 lines:
install.packages('devtools') #assuming it is not already installed
library(devtools)
install_github('andreacirilloac/updateR')
library(updateR)
updateR(admin_password = 'Admin user password')
I have the same problem with my dynlm package. I get the same error. But as R states pbkrtest is required. This package isn't available under R 3.2.3.
However you can download the package online, look a bit further on this site, the question is already asked on stackoverflow and they gave a site where you can find the packages. Then write the following code:
install.packages("...",repos = NULL, type="source")
install.packages("pbkrtest", dependencies = TRUE)
In the first line, here I wrote the 3 dots you need to write the path to the file where you placed the pbkrtest-package.
I also faced the same problem with caret package and I could solve it as the following:
install.packages("lme4", dependencies = TRUE)
library(lme4)
methods(sigma)
install.packages("pbkrtest", dependencies = TRUE)
library(caret)
This worked for me!
Try
install.packages('DEoptimR')
and followed by
install.packages("caret", dependencies = TRUE)
I had the same issues. Both of these commands worked for me.
I faced the same error with caret and none of the above suggestions helped. My R version was 3.2 and current version is 3.4.
I installed the new version and the issue was resolved
I have faced this issue and tried many ways but followed r console about error thrown and started downloading packages one by one. steps noted down what i did for this. y r studio version is "R version 3.4.4"
First install.packages("caret"), install.packages("ggplot2"), install.packages("lattice"), install.packages("lava")..
then load library(ggplot2) then library(lattice) then library(lava) and then finally library(caret).
What i believe that caret have these packages dependency so once caret is installed ideally 'install.packages('caret', dependencies = TRUE)' should work but it was not working in my R version so i did the step as given above and it worked for me.
hope it may work if someone get this issue
I did try all the above mentioned ways to install and activate caret but none worked for me.
finally what I did was to go to my drive location where R libraries are located. I removed a folder called "caret" and then in R studio I run "remove.packeges("caret")" to remove the caret package.
then I reinstalled the package.
install.packages("caret")
library(caret)
it worked for me.
I'm in R 3.6.1 and got the same error today.
I used this code:
install.packages("caret",dep = TRUE)
install.packages("ggplot2")
install.packages("lattice")
install.packages("lava")
install.packages("purrr")
library(ggplot2)
library(lattice)
library(lava)
library(purrr)
library(caret)
And now it works fine for me. It's all about dependencies that you should install with caret.
Use this:
install.packages(c("ggplot2", "lattice", "lava", "purrr", "caret"))
library(c("ggplot2", "lattice", "lava", "purrr", "caret"))
If that doesn't work, create a folder (R_LIB in this case) on your computer (documents in this case) and include the folder location as follow:
install.packages(c("ggplot2", "lattice", "lava", "purrr", "caret"), lib = "C:/documents/R_LIB")
library(c("ggplot2", "lattice", "lava", "purrr", "caret"), lib = "C:/documents/R_LIB")

Getting StringIndexOutOfBoundsException when attempting to create a new Form in Codenameone

I am using Netbeans and updated to use the latest codenameone plugin. I am trying to follow the walkthrough tutorial at http://www.codenameone.com/blog/gui-builder-walkthru.html, but I keep on getting a StringIndexOutOfBoundsException when attempting to generate a new Form using the NewGuiBuilderWizardIterator. The following is the stacktrace that I'm seeing. Any and all help would be greatly appreciated!
SEVERE [com.codename1.actions.OpenGuiBuilderAction]: Relative path com\mycompany\myapp\MyApp.java
SEVERE [com.codename1.actions.OpenGuiBuilderAction]: Gui file C:\Users\joshua\Documents\NetBeansProjects\TestGui1\res\guibuilder\com\mycompany\myapp\MyApp.gui
SEVERE [com.codename1.actions.OpenGuiBuilderAction]: Props C:\Users\joshua\Documents\NetBeansProjects\TestGui1\codenameone_settings.properties
SEVERE [com.codename1.actions.OpenGuiBuilderAction]: The GUI file doesn't exist!
WARNING [org.openide.filesystems.Ordering]: Found same position 100 for both Loaders/application/res/Actions/org-openide-actions-OpenAction.shadow and Loaders/application/res/Actions/sep-1.instance
WARNING [org.netbeans.modules.java.JavaTemplateAttributesProvider]: No classpath was found for folder: C:\Users\joshua\Documents\NetBeansProjects\TestGui1#b78894d2:1aed2d64
WARNING [org.openide.WizardDescriptor]
java.lang.StringIndexOutOfBoundsException: String index out of range: -4
at java.lang.String.substring(String.java:1919)
at com.codename1.NewGuiBuilderWizardIterator.instantiate(NewGuiBuilderWizardIterator.java:95)
at org.openide.loaders.TemplateWizard$InstantiatingIteratorBridge.instantiate(TemplateWizard.java:1046)
at org.openide.loaders.TemplateWizard.handleInstantiate(TemplateWizard.java:605)
at org.openide.loaders.TemplateWizard.instantiateNewObjects(TemplateWizard.java:439)
at org.openide.loaders.TemplateWizardIterImpl.instantiate(TemplateWizardIterImpl.java:248)
at org.openide.loaders.TemplateWizardIteratorWrapper.instantiate(TemplateWizardIteratorWrapper.java:160)
at org.openide.WizardDescriptor.callInstantiateOpen(WizardDescriptor.java:1629)
at org.openide.WizardDescriptor.callInstantiate(WizardDescriptor.java:1570)
at org.openide.WizardDescriptor.access$2300(WizardDescriptor.java:92)
[catch] at org.openide.WizardDescriptor$Listener$2$1.run(WizardDescriptor.java:2257)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1423)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2033)
You need to select a package when you do this and not the top level project since the code won't recognize that situation and won't know where to place the GUI file.
Notice that since an XML GUI file is created in the background, refactoring after the fact won't work well so this isn't something we should generally fix.

Access to shared_path in deploy.rb

I try to set command map using shared_path like that:
SSHKit.config.command_map[:composer] = "php #{shared_path.join('composer.phar')}"
But the path is /var/www/xxx not using the path I set on :deploy_to deploy/staging.rb.
I guess this is because staging.rb is loaded after.
What the right way then?
I had the same issue and although I don't think I have found the best way. I have found a way.
My default :deploy_to in deploy.rb points to '/var/www/my_app'. And I have a development stage where the server uses the same path. But my production server uses '/home/httpd/something/else' so I put :deploy_to in production.rb expecting it to deploy to that path. And everything works except the composer command. The composer.phar file is downloaded to the correct shared path and the files are deployed correctly. But when composer runs it tries to find it in '/var/www/my_app/shared'.
What I did was instead of putting the SSHKit.config.command_map by it self in deploy.rb, put it in a task. Something like:
namespace :deploy do
before :starting, :map_composer_command do
on roles(:app) do |server|
SSHKit.config.command_map[:composer] = "#{shared_path.join("composer.phar")}"
end
end
...
end
It feels like SSHKit.config.command_map runs "to early" or something. This seems to help. It works for me at least. And I had the exact same issue.
Edit:
I got some help from an issue I posted on capistrano/composer.

Tomcat 7 - Retrieve the version of a webapp (versioned WAR)

I've been unable to find any easy way of figuring out the version string for a WAR file deployed with Tomcat 7 versioned naming (ie app##version.war). You can read about it here and what it enables here.
It'd be nice if there was a somewhat more supported approach other than the usual swiss army knife of reflection powered ribcage cracking:
final ServletContextEvent event ...
final ServletContext applicationContextFacade = event.getServletContext();
final Field applicationContextField = applicationContextFacade.getClass().getDeclaredField("context");
applicationContextField.setAccessible(true);
final Object applicationContext = applicationContextField.get(applicationContextFacade);
final Field standardContextField = applicationContext.getClass().getDeclaredField("context");
standardContextField.setAccessible(true);
final Object standardContext = standardContextField.get(applicationContext);
final Method webappVersion = standardContext.getClass().getMethod("getWebappVersion");
System.err.println("WAR version: " + webappVersion.invoke(standardContext));
I think the simplest solution is using the same version (SVN revision + padding as an example) in .war, web.xml and META-INF/MANIFEST.MF properties files, so you could retrieve the version of these files later in your APP or any standard tool that read version from a JAR/WAR
See MANIFEST.MF version-number
Another solution described here uses the path name on the server of the deployed WAR. You'd extract the version number from the string between the "##" and the "/"
runningVersion = StringUtils.substringBefore(
StringUtils.substringAfter(
servletConfig.getServletContext().getRealPath("/"),
"##"),
"/");
Starting from Tomcat versions 9.0.32, 8.5.52 and 7.0.101, the webapp version is exposed as a ServletContext attribute with the name org.apache.catalina.webappVersion.
Link to the closed enhancement request: https://bz.apache.org/bugzilla/show_bug.cgi?id=64189
The easiest way would be for Tomcat to make the version available via a ServletContext attribute (org.apache.catalina.core.StandardContext.webappVersion) or similar. The patch to do that would be trivial. I'd suggest opening an enhancement request in Tomcat's Bugzilla. If you include a patch then it should get applied fairly quickly.

Resources