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

Searching for csproj, fsproj that uses Microsoft.Net.Sdk.Web #10704

Merged
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a24e39a
Searching for csproj, vbproj, fsproj using sdk Microsoft.Net.Sdk.Web
issacnitinmsft Jun 20, 2019
cef0696
Merge branch 'master' of https://github.com/Microsoft/azure-pipelines…
issacnitinmsft Jun 20, 2019
b2497ae
Updating package.json
issacnitinmsft Jun 20, 2019
7391524
Updating error message
issacnitinmsft Jun 20, 2019
b32a031
Review comments
issacnitinmsft Jun 21, 2019
b4ea957
Review comments
issacnitinmsft Jun 21, 2019
18b34f0
Try-catch
issacnitinmsft Jun 21, 2019
f6fdbea
Iteratively find and check for file encodings
issacnitinmsft Jun 21, 2019
230f4d8
Review comments
issacnitinmsft Jun 21, 2019
44ab483
Supporting only utf encodings
issacnitinmsft Jun 21, 2019
ec18b03
Merge branch 'master' of https://github.com/Microsoft/azure-pipelines…
issacnitinmsft Jun 24, 2019
98f0500
L0
issacnitinmsft Jun 24, 2019
ab684de
Adding semicolons
issacnitinmsft Jun 24, 2019
f3608b6
Merge branch 'master' into users/nijoy/dotnetcorecliv2_improve_webpro…
issacnitin Jun 24, 2019
c04b69f
Merge branch 'master' into users/nijoy/dotnetcorecliv2_improve_webpro…
issacnitin Jun 25, 2019
302f166
Removing vbproj
issacnitinmsft Jun 25, 2019
a90e273
Merge branch 'users/nijoy/dotnetcorecliv2_improve_webproject_detectio…
issacnitinmsft Jun 25, 2019
4fa6237
Comments
issacnitinmsft Jun 25, 2019
1e585f4
Merge branch 'master' into users/nijoy/dotnetcorecliv2_improve_webpro…
issacnitin Jun 25, 2019
904ce69
Merge branch 'master' into users/nijoy/dotnetcorecliv2_improve_webpro…
issacnitin Jun 25, 2019
ce2175c
Updating error message
issacnitinmsft Jun 25, 2019
db7d2be
Merge branch 'users/nijoy/dotnetcorecliv2_improve_webproject_detectio…
issacnitinmsft Jun 25, 2019
62570a9
Updating error message
issacnitinmsft Jun 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"loc.messages.dotnetCommandFailed": "Dotnet command failed with non-zero exit code on the following projects : %s",
"loc.messages.noProjectFilesFound": "Project file(s) matching the specified pattern were not found.",
"loc.messages.noPublishFolderFoundToZip": "A publish folder could not be found to zip for project file: %s.",
"loc.messages.noWebProjectFound": "No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory. You can set Publish Web Projects property to false (publishWebProjects: false in yml) if your project doesn't follow this convention or if you want to publish projects other than web projects.",
"loc.messages.noWebProjectFound": "No web project was found in the repository. Web projects are identified by presence of either a web.config file, wwwroot folder in the directory, or by the usage of Microsoft.Net.Web.Sdk in your csproj file. You can set Publish Web Projects property to false (publishWebProjects: false in yml) if your project doesn't follow this convention or if you want to publish projects other than web projects.",
issacnitin marked this conversation as resolved.
Show resolved Hide resolved
"loc.messages.zipFailed": "Zip failed with error: %s",
"loc.messages.Error_ApiKeyNotSupported": "DotNetCore currently does not support using an encrypted Api Key.",
"loc.messages.Error_ExpectedConfigurationElement": "Invalid xml. Expected element named 'configuration'.",
Expand Down
13 changes: 13 additions & 0 deletions Tasks/DotNetCoreCLIV2/Tests/L0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,19 @@ describe('DotNetCoreExe Suite', function () {
done();
});


it('publish works with publishWebProjects option if .csproj have Microsoft.Net.Sdk.Web', (done: MochaDone) => {
process.env["__projects__"] = "havesdk*/*.csproj;";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how is this test testing your new feature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are mocking inputfile argument and defining a mapping for the argument, then we're mocking the output of that definition as well.

process.env["__publishWebProjects__"] = "true";
let tp = path.join(__dirname, 'publishInputs.js')
let tr: ttm.MockTestRunner = new ttm.MockTestRunner(tp);
tr.run();

assert(tr.invokedToolCount == 1, 'should have invoked been invoked once');
assert(tr.succeeded, 'task should have failed');
done();
})

it('publish updates the output with the project name appended', (done: MochaDone) => {
process.env["__projects__"] = "*customoutput/project.json";
process.env["__publishWebProjects__"] = "false";
Expand Down
6 changes: 6 additions & 0 deletions Tasks/DotNetCoreCLIV2/Tests/publishInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"code": 1,
"stdout": "not published",
"stderr": ""
},
"dotnet publish havesdk/project.csproj": {
"code": 0,
"stdout": "published",
"stderr": ""
}
},
"findMatch": {
Expand All @@ -98,6 +103,7 @@ let a: ma.TaskLibAnswers = <ma.TaskLibAnswers>{
"*fail*/project.json": [],
"*customoutput/project.json": ["web3/project.json", "lib2/project.json"],
"dummy/project.json": ["dummy/project.json"],
"havesdk*/*.csproj": ["havesdk/project.csproj"],
"" : []
}
};
Expand Down
41 changes: 35 additions & 6 deletions Tasks/DotNetCoreCLIV2/dotnetcore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import tl = require("azure-pipelines-task-lib/task");
import tr = require("azure-pipelines-task-lib/toolrunner");
import path = require("path");
import fs = require("fs");
import ltx = require("ltx");
issacnitin marked this conversation as resolved.
Show resolved Hide resolved
var archiver = require('archiver');

import * as packCommand from './packcommand';
Expand Down Expand Up @@ -250,7 +251,7 @@ export class dotNetExe {
}

private extractOutputArgument(): void {
if (!this.arguments || !this.arguments.trim()) {
if (!this.arguments || !this.arguments.trim()) {
return;
}

Expand Down Expand Up @@ -325,22 +326,50 @@ export class dotNetExe {
}

var projectFiles = utility.getProjectFiles(projectPattern);
var resolvedProjectFiles: string[] = [];

if (searchWebProjects) {
projectFiles = projectFiles.filter(function (file, index, files): boolean {
resolvedProjectFiles = projectFiles.filter(function (file, index, files): boolean {
var directory = path.dirname(file);
return tl.exist(path.join(directory, "web.config"))
|| tl.exist(path.join(directory, "wwwroot"));
});

if (!projectFiles.length) {
tl.error(tl.loc("noWebProjectFound"));
}
if (!resolvedProjectFiles.length) {
var projectFilesUsingWebSdk = projectFiles.filter(this.isWebSdkUsed);
if(!projectFilesUsingWebSdk.length) {
tl.error(tl.loc("noWebProjectFound"));
}
return projectFilesUsingWebSdk;
}
return resolvedProjectFiles;
}

return projectFiles;
}

private isWebSdkUsed(projectfile: string): boolean {
if (projectfile.endsWith('.vbproj')) return false

try {
var fileBuffer: Buffer = fs.readFileSync(projectfile);
issacnitin marked this conversation as resolved.
Show resolved Hide resolved
var webConfigContent: string;

var fileEncodings = ['utf8', 'utf16le'];

for(var i = 0; i < fileEncodings.length; i++) {
tl.debug("Trying to decode with " + fileEncodings[i]);
webConfigContent = fileBuffer.toString(fileEncodings[i]);
issacnitin marked this conversation as resolved.
Show resolved Hide resolved
sachinma marked this conversation as resolved.
Show resolved Hide resolved
try {
var projectSdkUsed: string = ltx.parse(webConfigContent).getAttr("sdk") || ltx.parse(webConfigContent).getAttr("Sdk");
return projectSdkUsed && projectSdkUsed.toLowerCase() == "microsoft.net.sdk.web";
} catch (error) {}
issacnitin marked this conversation as resolved.
Show resolved Hide resolved
}
} catch(error) {
tl.warning(error);
}
return false;
}

private isPublishCommand(): boolean {
return this.command === "publish";
}
Expand Down
113 changes: 43 additions & 70 deletions Tasks/DotNetCoreCLIV2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Tasks/DotNetCoreCLIV2/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@
"dotnetCommandFailed": "Dotnet command failed with non-zero exit code on the following projects : %s",
"noProjectFilesFound": "Project file(s) matching the specified pattern were not found.",
"noPublishFolderFoundToZip": "A publish folder could not be found to zip for project file: %s.",
"noWebProjectFound": "No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory. You can set Publish Web Projects property to false (publishWebProjects: false in yml) if your project doesn't follow this convention or if you want to publish projects other than web projects.",
"noWebProjectFound": "No web project was found in the repository. Web projects are identified by presence of either a web.config file, wwwroot folder in the directory, or by the usage of Microsoft.Net.Web.Sdk in your project file. You can set Publish Web Projects property to false (publishWebProjects: false in yml) if your project doesn't follow this convention or if you want to publish projects other than web projects.",
"zipFailed": "Zip failed with error: %s",
"Error_ApiKeyNotSupported": "DotNetCore currently does not support using an encrypted Api Key.",
"Error_ExpectedConfigurationElement": "Invalid xml. Expected element named 'configuration'.",
Expand Down