<#@ template debug=
"false"
hostspecific=
"true"
language=
"C#"
#>
<#@ assembly name=
"System.Core"
#>
<#@ assembly name=
"Microsoft.VisualStudio.Shell.Interop.8.0"
#>
<#@ assembly name=
"EnvDTE"
#>
<#@ assembly name=
"EnvDTE80"
#>
<#@ assembly name=
"Microsoft.VisualStudio.TeamFoundation.VersionControl"
#>
<#@ assembly name=
"Microsoft.TeamFoundation.Client"
#>
<#@ assembly name=
"Microsoft.TeamFoundation.Common"
#>
<#@ assembly name=
"Microsoft.TeamFoundation"
#>
<#@ assembly name=
"Microsoft.TeamFoundation.WorkItemTracking.Client"
#>
<#@ assembly name=
"Microsoft.TeamFoundation.VersionControl.Client"
#>
<#@ assembly name=
"Microsoft.TeamFoundation.ProjectManagement"
#>
<#@ import
namespace
=
"Microsoft.TeamFoundation.Client"
#>
<#@ import
namespace
=
"Microsoft.TeamFoundation.VersionControl.Client"
#>
<#@ import
namespace
=
"System.Linq"
#>
<#@ import
namespace
=
"System.Text"
#>
<#@ import
namespace
=
"System.Text.RegularExpressions"
#>
<#@ import
namespace
=
"System.Collections.Generic"
#>
<#@ import
namespace
=
"EnvDTE"
#>
<#@ import
namespace
=
"EnvDTE80"
#>
<#@ output extension=
".cs"
#>
<#
DTE dte=
null
;
var
serviceProvider = Host
as
IServiceProvider;
if
(serviceProvider !=
null
) {
dte = serviceProvider.GetService(
typeof
(DTE))
as
DTE;
}
if
(dte ==
null
) {
throw
new
Exception(
"generate build number can only execute through the Visual Studio IDE"
);
}
ProjectItem projectItem = dte.Solution.FindProjectItem(Host.TemplateFile);
int
netVersion=0;
var
proj=projectItem.ContainingProject;
var
configmgr = proj.ConfigurationManager;
var
config = configmgr.ActiveConfiguration;
string
regex=
@"^.+?Version=v(?<version>\-?\d+\.\d+).*?$"
;
var
options = RegexOptions.Multiline;
string
input= proj.Properties.Item(
"TargetFrameworkMoniker"
).Value.ToString();
MatchCollection matches = Regex.Matches(input,regex,options);
foreach
(Match match
in
matches)
{
netVersion = (
int
)(
double
.Parse(match.Groups[
"version"
].Value)*100);
}
string
filePath = proj.FullName;
string
dirPath = System.IO.Path.GetDirectoryName(filePath);
var
wsInfo = Microsoft.TeamFoundation.VersionControl.Client.Workstation.Current.GetLocalWorkspaceInfo(filePath );
var
tpc =
new
TfsTeamProjectCollection(wsInfo.ServerUri);
var
vcServer = tpc.GetService<VersionControlServer>();
var
ws = vcServer.GetWorkspace(wsInfo);
var
versionSpec = VersionSpec.Latest;
var
historyParams =
new
QueryHistoryParameters(dirPath, RecursionType.Full);
historyParams.ItemVersion = versionSpec;
historyParams.VersionEnd = versionSpec;
historyParams.MaxResults = 1;
var
changeset = vcServer.QueryHistory(historyParams).FirstOrDefault();
var
dt = DateTime.Now;
var
userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
userName = userName.Split(
'\\'
).Last();
#>
using
System.Reflection;
using
System.Runtime.CompilerServices;
using
System.Runtime.InteropServices;
[assembly: AssemblyTitle(
"BuildTraceabilityDemo"
)]
[assembly: AssemblyDescription(
"BuildDate,<#=dt.ToString("
yyyyMMdd_HHmmss
")#>\r\n<#=proj.Properties.Item("
TargetFrameworkMoniker
").Value.ToString()#>\r\nBuild by,<#=userName#>\r\nConfig,<#=config.ConfigurationName#>,\r\nChangeset,<#=changeset.ChangesetId#>"
)]
[assembly: AssemblyConfiguration(
""
)]
[assembly: AssemblyCompany(
""
)]
[assembly: AssemblyProduct(
"BuildTraceabilityDemo"
)]
[assembly: AssemblyCopyright(
"Copyright © <#= dt.Year#>"
)]
[assembly: AssemblyTrademark(
""
)]
[assembly: AssemblyCulture(
""
)]
[assembly: ComVisible(
false
)]
[assembly: Guid(
"75ff7863-cb83-4d9b-80de-4a0de2781918"
)]
[assembly: AssemblyVersion(
"1.0.0.0"
)]
[assembly: AssemblyFileVersion(
"1.<#=dt.Year#>.<#=dt.Month#>.<#=dt.Day#>"
)]