') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); let user know working directory will be used as content root path by default by pedrobsaila · Pull Request #82445 · dotnet/runtime · GitHub
Skip to content

let user know working directory will be used as content root path by default - #82445

Merged
steveharter merged 4 commits into
dotnet:mainfrom
pedrobsaila:78789
Apr 26, 2023
Merged

let user know working directory will be used as content root path by default#82445
steveharter merged 4 commits into
dotnet:mainfrom
pedrobsaila:78789

Conversation

@pedrobsaila

Copy link
Copy Markdown
Contributor

Fixes#78789

@ghostghost added the community-contribution Indicates that the PR has been added by a community member label Feb 21, 2023
Logger.LogInformation("Hosting environment: {EnvName}", Environment.EnvironmentName);
Logger.LogInformation("Content root path: {ContentRoot}", Environment.ContentRootPath);

if (Path.GetFullPath(Environment.ContentRootPath).Equals(Path.GetFullPath("."), StringComparison.InvariantCultureIgnoreCase))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Path.GetFullPath(".")

Envrionment.CurrentDirectory?

InvariantCultureIgnoreCase

wrong on unix?

@pedrobsailapedrobsailaFeb 22, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Envrionment.CurrentDirectory ?

Envrionment.CurrentDirectory when !DisableDefaults, and AppContext.BaseDirectory elsewhere

wrong on unix?

This project uses OrdinalIgnoreCase for string comparison so I'm using Ordinal to be unix compliant

@jasper-djasper-d left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this be logged as info instead?

Some apps do not care about content root and would now need to explicitly configure it anyways or add extra logging config just to avoid that this warning pollutes observability systems.

@ghost

ghost commented Mar 1, 2023

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #78789

Author:pedrobsaila
Assignees:-
Labels:

area-Extensions-Hosting, community-contribution

Milestone:-

@steveharter
steveharter self-requested a review March 1, 2023 18:24
string contentRootFullPath = Path.GetFullPath(Environment.ContentRootPath);

if (contentRootFullPath.Equals(System.Environment.CurrentDirectory, StringComparison.Ordinal)
|| contentRootFullPath.Equals(AppContext.BaseDirectory, StringComparison.Ordinal))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When are these different?

@pedrobsailapedrobsailaMar 13, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

  • when DisableDefaults == false, it is System.Environment.CurrentDirectory :

    • code :

// In my testing, both Environment.CurrentDirectory and Environment.GetFolderPath(Environment.SpecialFolder.System) return the path without
// any trailing directory separator characters. I'm not even sure the casing can ever be different from these APIs, but I think it makes sense to
// ignore case for Windows path comparisons given the file system is usually (always?) going to be case insensitive for the system path.
stringcwd=Environment.CurrentDirectory;
if(!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)||!string.Equals(cwd,Environment.GetFolderPath(Environment.SpecialFolder.System),StringComparison.OrdinalIgnoreCase))
{
hostConfigBuilder.AddInMemoryCollection(new[]
{
newKeyValuePair<string,string?>(HostDefaults.ContentRootKey,cwd),
});
}
}

  • test :

https://github.com/dotnet/runtime/blob/d3f7d59e8dc44e5ce22c8ec9c011a1b72d7e9e92/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostApplicationBuilderTests.cs#LL519C9-L524C10

  • else it is AppContext.BaseDirectory :

    • code :

varhostingEnvironment=newHostingEnvironment()
{
EnvironmentName=hostConfiguration[HostDefaults.EnvironmentKey]??Environments.Production,
ContentRootPath=ResolveContentRootPath(hostConfiguration[HostDefaults.ContentRootKey],AppContext.BaseDirectory),
};

  • test :

https://github.com/dotnet/runtime/blob/d3f7d59e8dc44e5ce22c8ec9c011a1b72d7e9e92/src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostApplicationBuilderTests.cs#LL251C9-L283C10

@pedrobsailapedrobsailaMar 13, 2023

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I'm not sure if there's a case when they have different values, but the two seems different by looking at their code

@dotnetdotnet deleted a comment from azure-pipelinesBotApr 19, 2023
@dotnetdotnet deleted a comment from azure-pipelinesBotApr 19, 2023
@steveharter

Copy link
Copy Markdown
Contributor

/azp run runtime-dev-innerloop

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@steveharter

Copy link
Copy Markdown
Contributor

There are a few CI errors; re-running

@steveharter

Copy link
Copy Markdown
Contributor

/azp run runtime

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@steveharter
steveharter merged commit c958573 into dotnet:mainApr 26, 2023
@pedrobsaila
pedrobsaila deleted the 78789 branch April 27, 2023 07:26
steveharter added a commit to steveharter/runtime that referenced this pull request May 10, 2023
steveharter added a commit that referenced this pull request May 10, 2023
@steveharter

Copy link
Copy Markdown
Contributor

@pedrobsaila there were concerns with this expressed in #85809. Please see that issue. Thanks.

@ghostghost locked as resolved and limited conversation to collaborators Jun 10, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Extensions-Hostingcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explictily log working directory and let user know it will be used as content root path by default.

5 participants

@pedrobsaila@steveharter@jasper-d@kasperk81@buyaa-n