How to get Version Number by Build Number Office - ms-word

I'm working VSTO and I have an issue.
I want to get a Version of Office but I can't
I want to get 2008
Please help me! Thanks
I'm using C#

You can get the file version information of the Office application.
// Retrieve the path e.g. from the InstallRoot Registry key
var fileVersionInfo = FileVersionInfo.GetVersionInfo(#"C:\Program Files (x86)\Microsoft Office\root\Office16\WINWORD.EXE");
var version = new Version(fileVersionInfo.FileVersion);
// or you can get the information from the running instance using the `Process` class
var process = Process.GetProcessesByName("winword").First();
string fileVersionInfo = process.MainModule.FileVersionInfo.FileVersion;
var version = Version(fileVersionInfo);

Related

How to show PDF from .net maui app on Windows

I am just trying to show a PDF file from my .NET MAUI application on Windows and it is giving me the error below.
"System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'C:\Users<username>\Documents\helpfile.pdf' with working directory 'C:\WINDOWS\system32'. The specified executable is not a valid application for this OS platform.'"
My code is below. It has worked in a WPF app but won't work here.
Process.Start("C:\\Users\\<username>\\Documents\\helpfile.pdf"); // removed the username here and above in error message
also tried: (getting helpfile.pdf from install directory)
string _asmPath = Assembly.GetExecutingAssembly().Location;
int lastIndex = _asmPath.LastIndexOf('\\');
string helpfilePath = $"{_asmPath.Substring(0, lastIndex)}\\helpfile.pdf";
ProcessStartInfo startInfo = new ProcessStartInfo(helpfilePath);
Process.Start(startInfo);
and I get a similar error:
"System.ComponentModel.Win32Exception: 'An error occurred trying to start process 'C:\Projects\SnapSignalTel\bin\Debug\net6.0-windows10.0.19041.0\win10-x64\AppX\helpfile.pdf' with working directory 'C:\WINDOWS\system32'. The specified executable is not a valid application for this OS platform.'"
How can I open this PDF document (helpfile.pdf) in a MAUI app on Win10?
Thanks for any help!
use Launcher
await Launcher.Default.OpenAsync(new OpenFileRequest("Some Title", new ReadOnlyFile(filepath)));

DB2 with .NET Core 2.1

I installed IBM.Data.DB2.Core Version (1.2.2.100) with Visual Studio 2017 & .Net Core 2.1. I was trying to test simple DB2 (z/OS server) connection and getting the below error. Our DB2 Server type is OS390 and version is 11.
ERROR [42968] [IBM] SQL1598N An attempt to connect to the database server failed because of a licensing problem.
using (DB2Connection con = new DB2Connection("Server=xxxx.xxxx.com:446;Database=XXXX;UID=XXXXXX;PWD=xxxxx"))
{
try
{
con.Open();
}
catch (Exception ex)
{
throw ex;
}
}
Also I copied the license file to .nuget\packages\ibm.data.db2.core\1.2.2.100\build\clidriver\license folder.
I tried everything mentioned here:
https://www.ibm.com/developerworks/community/blogs/96960515-2ea1-4391-8170-b0515d08e4da/entry/Instructions_for_downloading_and_using_DB2_NET_Core_provider_package?lang=en
Any thoughts?
Spent a few hours on this and here is what worked for me using current latest version of the package 1.3.0.100 and a valid DB2 11.1 license I already had installed. I suspect this approach will work on 1.1 and 1.2 as well, assuming you have the license already.
Add the following block to your project file, adjusting the path for DB2License as necessary for your local setup:
<ItemGroup>
<DB2License Include="C:\ProgramData\IBM\DB2\{FOLDER NAME THAT VARIES BY INSTALL}\license\**\*.*"/>
</ItemGroup>
<Target Name="CopyFiles" AfterTargets="AfterBuild">
<Copy SourceFiles="#(DB2License)" DestinationFolder="$(OutDir)\clidriver\license\" />
</Target>
The important part seems to be that $(OutDir)\clidriver\license\ has all files necessary to represent a valid DB2 11.1+ license before your application runs. For me there were 3 files. For server build and release, a slightly more complex setup may be necessary to get the correct files to the expected location.
Here are other things I tried that did not seem to help for me, but may help for others:
Some articles on IBM's site suggest adding %userprofile%\.nuget\packages\IBM.Data.DB2.Core\<version>\build\clidriver\bin or %userprofile%\.nuget\packages\IBM.Data.DB2.Core\<version>\build\clidriver\license to your PATH environment variable. This seems to be completely unnecessary.
Other articles or forum posts suggest copying your license files to the nuget package license folder %userprofile%\.nuget\packages\IBM.Data.DB2.Core\<version>\build\clidriver\license. This worked, but isn't ideal since it needs to be done on each machine after nuget package restore and then re-done if you change versions of the nuget package later on. And of course none of the places mentioning "hey just copy the license to this path" specified the default directory that contains your existing license: C:\ProgramData\IBM\DB2\{FOLDER NAME THAT VARIES BY INSTALL}\license\.
IBM DB2 Nuget package for .net core version 1.1 & 1.2 comes with DB2 Driver version 11. These two packages doesn't support if you have DB2 version less than 11. Here are the steps to resolve this issue.
Install IBM DB2 Nuget package version 1.0
Update your environment PATH variable with 1.0 installation path
Remove/Un-install any other DB2 driver installed on your machine
Close your Visual studio version and reopen it, it will work without any issue.
Also, 1.0 version doesn't require the license file. Hope this helps.
You can use this tutorial
https://www.ibm.com/support/knowledgecenter/SSFMBX/com.ibm.swg.im.dashdb.doc/connecting/connect_connecting__net_applications.html
/CODE EXAMPLE/
using System;
using IBM.Data.DB2;
namespace dotNetSSLTest
{
class Program
{
static void Main(string[] args)
{
DB2Command MyDB2Command = null;
// Use the dsn alias that you defined in db2dsdriver.cfg with the db2cli writecfg command in step 1.
String MyDb2ConnectionString = "database=alias;uid=userid;pwd=password;";
DB2Connection MyDb2Connection = new DB2Connection(MyDb2ConnectionString);
MyDb2Connection.Open();
MyDB2Command = MyDb2Connection.CreateCommand();
MyDB2Command.CommandText = "SELECT branch_code, city from GOSALES.BRANCH";
Console.WriteLine(MyDB2Command.CommandText);
DB2DataReader MyDb2DataReader = null;
MyDb2DataReader = MyDB2Command.ExecuteReader();
Console.WriteLine("BRANCH\tCITY");
Console.WriteLine("============================");
while (MyDb2DataReader.Read())
{
for (int i = 0; i <= 1; i++)
{
try
{
if (MyDb2DataReader.IsDBNull(i))
{
Console.Write("NULL");
}
else
{
Console.Write(MyDb2DataReader.GetString(i));
}
}
catch (Exception e)
{
Console.Write(e.ToString());
}
Console.Write("\t");
}
Console.WriteLine("");
}
MyDb2DataReader.Close();
MyDB2Command.Dispose();
MyDb2Connection.Close();
}
}
}

Set TFS build version number PowerShell

I know that similar question already exist, but I cannot find appropriate answer.
My question is: Is it possible to set new build version number int TFS with PowerShell?
I want to create build version number and set through PowerShell. I want exactly like that, no other solutions.
Thanks
How about this?
# Change the following to your TFS collection and build URIs...
# These environment variables will exist during TFS builds
[String] $CollectionUrl = "$env:TF_BUILD_COLLECTIONURI"
[String] $BuildUrl = "$env:TF_BUILD_BUILDURI"
# Get the Team Project Collection:
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl)
# Connect to the TFS build service:
$buildServer = $teamProjectCollection.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
# Get the build detail:
$buildDetail = $buildServer.GetBuild($BuildUrl)
# Updating the TFS build number with an example SemVer:
$buildDetail.BuildNumber = "1.2.3-alpha1"
# Make sure to save the changes:
$buildDetail.Save()

Entity Framework Power Tools Reverse Engineer Code First into a folder

I'm using Entity Framework Power Tools Reverse Engineer Code First to generate my POCO classes, mapping files, and context from the database. I was able to change the T4 templates to generate a different namespace based on my database schema, but I am not able to find how to create a folder based on the tables schema and place the related POCO classes in the folder.
Could somebody help?
Thanks
The folders for the model (and the mappings) are hard-coded in the tool. Reverse-engineering EfPowerTools.dll shows the following lines in method ReverseEngineerCodeFirst of ReverseEngineerCodeFirstHandler:
string str3 = str2 + ".Models";
string path1_1 = Path.Combine(directory.FullName, "Models");
string str4 = str3 + ".Mapping";
string path1_2 = Path.Combine(path1_1, "Mapping");
So, too bad, you can't change the name and location of these folders.
I'd have to add another answer as I have tried the approach suggested in my previous one and that didn't work. I have changed EF Power Tools in order to output files to different folder or project.
You need to install the following EF Power Tools Extension (https://entityframework.codeplex.com/SourceControl/network/forks/khorvat/EFPowerToolsEx)
Use this code to accomplish the export
var efHost = (EfTextTemplateHost)Host;
var code = new CodeGenerationTools(this);
var dte = efHost.DTE;
EnvDTE.Project ModelProject = null;
foreach(EnvDTE.Project dteProject in dte.Solution)
{
if (dteProject.Name.Equals("YourModelProjectName"))
ModelProject = dteProject;
}
var ModelProjectDirectory = new FileInfo(ModelProject.FullName).Directory;
var ModelProjectNamespace = (string)ModelProject.Properties.Item("RootNamespace").Value;
string ModelNameSpace = ModelProjectNamespace + ".Model";
string outputPath = Path.Combine(ModelProjectDirectory + ModelExportPath + #"Generated\I" + efHost.EntityType.Name + ".cs");
Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
if (ModelProject.DTE.SourceControl.IsItemUnderSCC(outputPath) && !ModelProject.DTE.SourceControl.IsItemCheckedOut(outputPath))
ModelProject.DTE.SourceControl.CheckOutItem(outputPath);
File.WriteAllText(outputPath, this.GenerationEnvironment.ToString());
ModelProject.ProjectItems.AddFromFile(outputPath);
this.GenerationEnvironment.Clear();
With this you will be able to export output to another file, folder and even a project.
Update
As mentioned in other answer this approach won't work. So the answer is no longer applied.
You can try resolving the output path and create a folder by doing the following:
<## import namespace="System.IO" #>
var efHost = (EfTextTemplateHost)Host;
var outputPath = Path.Combine(Path.GetDirectoryName(efHost.TemplateFile), "YourFolder");
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
Now to output to different folder you can try using the GenerationEnvironment similar to this:
<## dte processor="T4Toolbox.DteProcessor" #>
<## TransformationContext processor="T4Toolbox.TransformationContextProcessor" #>
<## assembly name="System.Xml" #>
<## assembly name="EnvDTE" #>
<## import namespace="T4Toolbox" #>
ProcessOutputTemplate template = new ProcessOutputTemplate(this.GenerationEnvironment.ToString());
template.Output.File = outputPath;
template.Render();
this.GenerationEnvironment.Clear();
Note: this approach requires the T4 Toolbox installed in the VS 2012/13 - http://www.olegsych.com/t4toolbox/ (http://www.olegsych.com/t4toolbox/gettingstarted/)
I have modified the EFPowerTool extension to support the namespace based directory structure creation. Created a pull request on EF 6.x project at codeplex. Also I have created an experimental branch on github for testing purpose.(There surely are room for fixes/enhancement which can be added and tested before sending updated pull request)
You can download the extension installer with the proposed fix from here(see install dir in source).

EF Migrations migrate.exe generate script

I'm playing around with Entity framework and continuous builds. So far i'm able to run a migration or series of migrations without any problem by using migrate.exe and the appropriate arguments.
However, i've hit trouble when trying to get migrate.exe to kick out a script, rather than perform the migration, in the same way as I could get by running
update-database -TargetMigration TestMigration -script
from within Package Manager Console in Visual Studio.
Is there currently a way to do this?
Thanks.
Since the 10/22/2017 you can do it thanks to this PR:
https://github.com/aspnet/EntityFramework6/commit/02ec6b8c9279f93f80eeed1234e5ce0acfce5f31
Here the Entity Framework 6.2 release notes that implements this functionality (see 'Migrate.exe should support -script option' section):
https://blogs.msdn.microsoft.com/dotnet/2017/10/26/entity-framework-6-2-runtime-released/
Follow those steps:
Copy the file migrate.exe from the '\packages\EntityFramework.6.2.0\tools' to the target 'bin' folder (for example on the production server) after that you deployed the new assembly that contains the new migrations
Open the command line in the folder and launch this command:
migrate.exe yourMigrationAssembly.dll
/startupConfigurationFile=”..\web.config”
/scriptFile="migrationOutput.sql"
It will generate the the file "migrationOutput.sql" that contains the SQL you have to execute on your target environment DB based on the migrations that are not yet applied on it.
It is currently not supported. Please add your vote to the issue: Migrations: -Script for Migrate.exe
I encountered the same problem and indeed the option is available in the package manager console in Visual Studio. So I opened up the powershell script and the entity framework dll and built a small executable so you can generate the scripts from command line.The source code is available as-is and without any warranty here;
EF6
EF5
You can write a simple c# console application or use something like Linqpad to generate the script using the Entity Framework Infrastructure objects. You will just need to load the DLL with your DbMigrationsConfiguration class and instantiate it. Here is the code similar to what is working for me:
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Migrations;
using System.Data.Entity.Migrations.Infrastructure;
const string ScriptFile = "Migration.sql";
const string ConnectionString = #"Server=.\SqlExpress;Database=...;Trusted_Connection=True;";
const bool AutomaticMigrationDataLossAllowed = false;
var targetDb = new DbConnectionInfo(ConnectionString, "System.Data.SqlClient");
var config = new MyDbMigrationsConfiguration
{
AutomaticMigrationDataLossAllowed = AutomaticMigrationDataLossAllowed,
TargetDatabase = targetDb,
};
var migrator = new DbMigrator(config);
var scripter = new MigratorScriptingDecorator(migrator);
var script = scripter.ScriptUpdate(null, null);
File.WriteAllText(ScriptFile, script);
Console.WriteLine("Migration Script Generated: " + ScriptFile);