JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<h1>Generate .csproj for .net standard</h1>
<p>Extracting package references from packages.config and project references from the old .csproj file to generate a new .net standard .csproj file
<br/>
Will also map the PCL profile version to the corresponding .net standard version based on this document: <a href="https://github.com/dotnet/standard/blob/master/docs/versions.md" target="_blank">https://github.com/dotnet/standard/blob/master/docs/versions.md</a>
<br/>Tested in latest versions of Firefox and Chrome. Will not work in IE or Edge</p>
<h3>1. Paste old .csproj</h3>
<p style="color:red" id="csprojErrorField"></p>
<textarea id="csproj"></textarea>
<h3>2. Paste packages.config</h3>
<p style="color:red" id="packageConfigErrorField"></p>
<textarea id="packageConfig"></textarea>
<h3>3. Here is your new .net standard 2.0 .csproj file</h3>
<textarea id="output" ></textarea>
<h3>Ps! Remember to delete assemblyreferences.cs and packages.config from your project</h3>
textarea{
width:100%;
height: 200px;
}
// Run when changes are detected in input text areas
document.getElementById("packageConfig").addEventListener('input',generate);
document.getElementById("csproj").addEventListener('input',generate);
function generate(){
// Clear error messages
document.getElementById("csprojErrorField").innerHtml = "";
document.getElementById("packageConfigErrorField").innerHtml = "";
// Parse xml document and get all package tags
var packages = getPackageArray();
var projectReferences = getProjectReferenceArray();
// Build new xml document containing packages
var xml = buildNewConfigFile(packages,projectReferences);
// Serialize xml document to string and output
var serializer = new XMLSerializer();
document.getElementById("output").value = serializer.serializeToString(xml);
}
function buildNewConfigFile(packages,projects){
// Need xml document to create tags
var xml = document.implementation.createDocument(null,"dontneed");
// Create root tag with attribute
var root = xml.createElement("Project");
root.setAttribute("Sdk","Microsoft.NET.Sdk");
// Set target framework
var targetFramework = xml.createElement("TargetFramework");
targetFramework.textContent = "netstandard" + getDotnetVersion();
var propertyGroup = xml.createElement("PropertyGroup");
propertyGroup.appendChild(targetFramework);
root.appendChild(propertyGroup);
// Add all packages
var itemGroup = xml.createElement("ItemGroup");
for(const p of packages){
var packageReference = xml.createElement("PackageReference");
packageReference.setAttribute("Include",p.name);
packageReference.setAttribute("Version",p.version);
itemGroup.appendChild(packageReference);
}
root.appendChild(itemGroup);
var projectItemGroup = xml.createElement("ItemGroup");
for(const p of projects){
var projectReference = xml.createElement("ProjectReference");
projectReference.setAttribute("Include",p);
projectItemGroup.appendChild(projectReference);
}
root.appendChild(projectItemGroup);
return root;
}
function getPackageArray(){
var packages = [];
const inputstring = document.getElementById("packageConfig").value;
const xml = new window.DOMParser().parseFromString(inputstring,"text/xml");
if(inputstring.length != 0)
checkXmlForErrors(xml,"packageConfigErrorField");
// Find all elements with tag name package
const xmlElements = xml.getElementsByTagName('package');
for(const x of xmlElements){
// Create obj for each package
var package = {
name: x.getAttribute("id"),
version: x.getAttribute("version")
};
packages.push(package);
}
return packages;
}
function getProjectReferenceArray(){
var projectPaths = [];
const inputstring = document.getElementById("csproj").value;
var xml = new window.DOMParser().parseFromString(inputstring,"text/xml");
if(inputstring.length != 0)
checkXmlForErrors(xml,"csprojErrorField");
// Find all elements with tag name ProjectReference
const xmlElements = xml.getElementsByTagName('ProjectReference');
for(const e of xmlElements){
projectPaths.push(e.getAttribute("Include"));
}
return projectPaths;
}
function checkXmlForErrors(xml, errorOutputFieldId){
var error = xml.getElementsByTagName("parsererror")[0];
if(error){
var errorMsg = error.getElementsByTagName("div")[0].textContent
document.getElementById(errorOutputFieldId).innerHTML = errorMsg;
}
else{
document.getElementById(errorOutputFieldId).innerHTML = "";
}
}
function mapStandard(version){
var versionNumber = version.replace(/[^0-9.]/g, "");
switch(parseInt(versionNumber)){
case 31:
case 49:
case 78:
case 84:
case 157:
case 259:
return "1.0";
case 7:
case 111:
return "1.1";
case 32:
case 44:
case 151:
return "1.2";
//When in doubt. Go for 2.0
default:
return "2.0";
}
}
function getDotnetVersion(){
const inputstring = document.getElementById("csproj").value;
const xml = new window.DOMParser().parseFromString(inputstring,"text/xml");
if(inputstring.length != 0)
checkXmlForErrors(xml,"packageConfigErrorField");
// Find all elements with tag name package
const xmlElements = xml.getElementsByTagName('TargetFrameworkProfile');
return mapStandard(xmlElements[0].innerHTML);
}
Also see: Tab Triggers