Improved code signing

.csproj properties used instead of assembly attributes
dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 9 years ago
parent 88a80ccdaf
commit 33f78ab092
  1. 36
      BuildServer/lib/tasks/dotnetrewrite.js
  2. 10
      DotNetBuilder/Compiler.cs

@ -29,39 +29,37 @@ module.exports = function (params, processor) {
((date.getHours() * 100 + date.getMinutes()) * 100 + date.getSeconds()) + " (" + ((date.getHours() * 100 + date.getMinutes()) * 100 + date.getSeconds()) + " (" +
"built from " + processor.context.rev + "; " + "built from " + processor.context.rev + "; " +
"repository: " + processor.context.owner + "/" + processor.context.reponame + "; " + "repository: " + processor.context.owner + "/" + processor.context.reponame + "; " +
"branch: " + processor.context.branch + ")"; "branch: " + processor.context.branch + ")",
processAssemblyInfo = function (content, cb) {
content += "\r\n";
content = addAssemblyAttribute(content, "[assembly: AssemblyInformationalVersion(\"" + version + "\")]");
return cb(null, content);
},
processCsproj = function (content, cb) {
if (!params.skipCodeSigning && !settings.skipCodeSigning) {
content = content.replace("</PropertyGroup>", "</PropertyGroup><PropertyGroup><SignAssembly>true</SignAssembly><AssemblyOriginatorKeyFile>" + settings.codeSigningKeyFile + "</AssemblyOriginatorKeyFile></PropertyGroup>");
}
return cb(null, content);
};
glob("**/AssemblyInfo.cs", {cwd: processor.context.exported}, function (err, files) { glob("**/{AssemblyInfo.cs,*.csproj}", {cwd: processor.context.exported}, function (err, files) {
if (err) { if (err) {
processor.onError(err); processor.onError(err);
return processor.done(); return processor.done();
} }
processor.onInfo("Found " + files.length + " AssemblyInfo.cs files"); processor.onInfo("Found " + files.length + " AssemblyInfo.cs/csproj files");
if (!files || !files.length) { if (!files || !files.length) {
processor.onWarn("No AssemblyInfo.cs found"); processor.onWarn("No AssemblyInfo.cs/csproj found");
return processor.done(); return processor.done();
} }
return async.parallel(files.map(function (file) { return async.parallel(files.map(function (file) {
return function (callback) { return function (callback) {
return async.waterfall([ return async.waterfall([
fs.readFile.bind(null, processor.context.exported + "/" + file), fs.readFile.bind(null, processor.context.exported + "/" + file, { encoding: "utf8" }),
function (content, cb) { (file.substr(-7).toLowerCase() == ".csproj") ? processCsproj : processAssemblyInfo,
content += "\r\n";
if (!params.skipCodeSigning && !settings.skipCodeSigning) {
content = content.replace(
/InternalsVisibleTo\s*\(\s*\"([\w.]+)\"\s*\)/g,
function (match, p1) {
return "InternalsVisibleTo(\"" + p1 + ",PublicKey=" + settings.codeSigningPublicKey + "\")";
}
);
content = addAssemblyAttribute(content, "[assembly: AssemblyKeyFileAttribute(\"" + settings.codeSigningKeyFile + "\")]\r\n");
}
content = addAssemblyAttribute(content, "[assembly: AssemblyInformationalVersion(\"" + version + "\")]");
return cb(null, content);
},
fs.writeFile.bind(null, processor.context.exported + "/" + file) fs.writeFile.bind(null, processor.context.exported + "/" + file)
], function (err) { ], function (err) {
if (err) { if (err) {

@ -44,21 +44,11 @@ namespace MicroBuildServer.DotNetBuilder
private void OnError(object sender, BuildErrorEventArgs e) private void OnError(object sender, BuildErrorEventArgs e)
{ {
if (e.Code == "CS1699")
{
//Use command line option '/keyfile' or appropriate project settings instead of 'AssemblyKeyFileAttribute' (#CS1699)
return;
}
Messages.Add(Response.Message.CreateError(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber))); Messages.Add(Response.Message.CreateError(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber)));
} }
private void OnWarning(object sender, BuildWarningEventArgs e) private void OnWarning(object sender, BuildWarningEventArgs e)
{ {
if (e.Code == "CS1699")
{
//Use command line option '/keyfile' or appropriate project settings instead of 'AssemblyKeyFileAttribute' (#CS1699)
return;
}
Messages.Add(Response.Message.CreateWarn(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber))); Messages.Add(Response.Message.CreateWarn(GetLine("{0} (#{1}, {2}:{3},{4})", e.Message, e.Code, e.File, e.LineNumber, e.ColumnNumber)));
} }

Loading…
Cancel
Save