css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

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.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

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);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console