Skip to content

Commit d38fb6e

Browse files
Copilotbwinsley
authored andcommitted
Update projects to .NET 8 - migrate C++/CLI and convert C# projects to SDK-style (JavascriptNet#112)
Co-authored-by: bwinsley <64841770+bwinsley@users.noreply.github.com>
1 parent fa46bbb commit d38fb6e

29 files changed

Lines changed: 881 additions & 370 deletions

.gitignore

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,12 @@ _ReSharper*/
2222
*.sdf
2323
*.opensdf
2424
TestResult.xml
25-
/.vs
25+
.vs/
2626
/Source/Noesis.Javascript/packages
27+
28+
# NuGet
29+
.nuget/
30+
packages/
31+
*.nupkg
32+
*.snupkg
33+

Fiddling/Fiddling.csproj

Lines changed: 18 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,32 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
1+
<Project Sdk="Microsoft.NET.Sdk">
42
<PropertyGroup>
5-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7-
<ProjectGuid>{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}</ProjectGuid>
83
<OutputType>Exe</OutputType>
9-
<AppDesignerFolder>Properties</AppDesignerFolder>
10-
<RootNamespace>Fiddling</RootNamespace>
11-
<AssemblyName>Fiddling</AssemblyName>
12-
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13-
<FileAlignment>512</FileAlignment>
14-
<TargetFrameworkProfile />
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
7+
<Platforms>AnyCPU;x64;x86</Platforms>
158
</PropertyGroup>
16-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
9+
10+
<PropertyGroup Condition="'$(Platform)'=='x64'">
1711
<PlatformTarget>x64</PlatformTarget>
18-
<DebugSymbols>true</DebugSymbols>
19-
<DebugType>full</DebugType>
20-
<Optimize>false</Optimize>
21-
<OutputPath>bin\Debug\</OutputPath>
22-
<DefineConstants>DEBUG;TRACE</DefineConstants>
23-
<ErrorReport>prompt</ErrorReport>
24-
<WarningLevel>4</WarningLevel>
25-
<Prefer32Bit>false</Prefer32Bit>
2612
<V8Platform>x64</V8Platform>
2713
</PropertyGroup>
28-
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<PlatformTarget>AnyCPU</PlatformTarget>
30-
<DebugType>pdbonly</DebugType>
31-
<Optimize>true</Optimize>
32-
<OutputPath>bin\Release\</OutputPath>
33-
<DefineConstants>TRACE</DefineConstants>
34-
<ErrorReport>prompt</ErrorReport>
35-
<WarningLevel>4</WarningLevel>
36-
<Prefer32Bit>false</Prefer32Bit>
37-
<V8Platform>x64</V8Platform>
38-
</PropertyGroup>
39-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
40-
<DebugSymbols>true</DebugSymbols>
41-
<OutputPath>bin\x86\Debug\</OutputPath>
42-
<DefineConstants>DEBUG;TRACE</DefineConstants>
43-
<DebugType>full</DebugType>
14+
15+
<PropertyGroup Condition="'$(Platform)'=='x86'">
4416
<PlatformTarget>x86</PlatformTarget>
45-
<ErrorReport>prompt</ErrorReport>
46-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
47-
<Prefer32Bit>false</Prefer32Bit>
4817
<V8Platform>Win32</V8Platform>
4918
</PropertyGroup>
50-
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
51-
<OutputPath>bin\x86\Release\</OutputPath>
52-
<DefineConstants>TRACE</DefineConstants>
53-
<Optimize>true</Optimize>
54-
<DebugType>pdbonly</DebugType>
55-
<PlatformTarget>x86</PlatformTarget>
56-
<ErrorReport>prompt</ErrorReport>
57-
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
58-
<Prefer32Bit>false</Prefer32Bit>
59-
<V8Platform>Win32</V8Platform>
19+
20+
<PropertyGroup Condition="'$(Platform)'=='AnyCPU'">
21+
<PlatformTarget>x64</PlatformTarget>
22+
<V8Platform>x64</V8Platform>
6023
</PropertyGroup>
24+
6125
<ItemGroup>
62-
<Reference Include="System" />
63-
<Reference Include="System.Core" />
64-
<Reference Include="System.Xml.Linq" />
65-
<Reference Include="System.Data.DataSetExtensions" />
66-
<Reference Include="Microsoft.CSharp" />
67-
<Reference Include="System.Data" />
68-
<Reference Include="System.Xml" />
69-
</ItemGroup>
70-
<ItemGroup>
71-
<Compile Include="Program.cs" />
72-
<Compile Include="Properties\AssemblyInfo.cs" />
26+
<ProjectReference Include="..\Source\Noesis.Javascript\JavaScript.Net.vcxproj" />
7327
</ItemGroup>
74-
<ItemGroup>
75-
<None Include="app.config" />
76-
</ItemGroup>
77-
<ItemGroup>
78-
<ProjectReference Include="..\Source\Noesis.Javascript\JavaScript.Net.vcxproj">
79-
<Project>{7ecfed5e-8b33-4065-acbf-ab1050fb0f4c}</Project>
80-
<Name>JavaScript.Net</Name>
81-
</ProjectReference>
82-
</ItemGroup>
83-
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
84-
<PropertyGroup>
85-
<PostBuildEvent>copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8.dll $(ProjectDir)$(OutDir)
86-
copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8_libbase.dll $(ProjectDir)$(OutDir)
87-
copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8_libplatform.dll $(ProjectDir)$(OutDir)
88-
copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\zlib.dll $(ProjectDir)$(OutDir)
89-
copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\icu*.* $(ProjectDir)$(OutDir)
90-
</PostBuildEvent>
91-
</PropertyGroup>
92-
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
93-
Other similar extension points exist, see Microsoft.Common.targets.
94-
<Target Name="BeforeBuild">
95-
</Target>
96-
<Target Name="AfterBuild">
28+
29+
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
30+
<Exec Command="copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8.dll $(ProjectDir)$(OutDir)&#xD;&#xA;copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8_libbase.dll $(ProjectDir)$(OutDir)&#xD;&#xA;copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\v8_libplatform.dll $(ProjectDir)$(OutDir)&#xD;&#xA;copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\zlib.dll $(ProjectDir)$(OutDir)&#xD;&#xA;copy $(ProjectDir)..\$(V8Platform)\$(Configuration)\icu*.* $(ProjectDir)$(OutDir)" />
9731
</Target>
98-
-->
9932
</Project>

Fiddling/Program.cs

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using System.Runtime.Remoting.Contexts;
54
using System.Text;
65
using Noesis.Javascript;
76

@@ -15,45 +14,72 @@ class Program
1514
{
1615
public class Product
1716
{
17+
public Product(decimal price)
18+
{
19+
Price = price;
20+
}
1821
public decimal Price { get; set; }
22+
public void DoSomething() { }
23+
public void DoSomethingElse() { }
24+
public IEnumerable<decimal> GetTaxes() => new List<decimal> { 0.01m, 0.02m };
25+
public decimal GetSalesTax(JavascriptFunction callback) => Convert.ToDecimal(callback.Call(Price));
26+
public override string ToString() => Price.ToString();
1927
}
2028

29+
// ...
30+
2131
static void Main(string[] args)
2232
{
33+
using (JavascriptContext context = new JavascriptContext())
34+
{
35+
try
36+
{
37+
// breakpoint here
38+
context.SetConstructor<Product>("Product", (Func<decimal, Product>)(price => new Product(price)));
39+
context.SetParameter("globalProduct", new Product(2));
40+
var result = context.Run($@"
41+
{{
42+
const importantProduct = new Product(3);
43+
let sum = 0;
44+
for (let i = 0; i < 200_000; i++) {{
2345
24-
JavascriptContext.SetFatalErrorHandler(FatalErrorHandler);
25-
using (JavascriptContext context = new JavascriptContext()) {
26-
//int[] ints = new[] { 1, 2, 3 };
27-
//_context.SetParameter("n", ints);
28-
//var result = _context.Run("n[1]");
29-
//Console.WriteLine(result.ToString());
30-
//_context.SetParameter("bozo", new Bozo(ints));
46+
// Commit 1 - creating managed objects from JS
47+
const product = new Product(Math.random());
3148
32-
context.SetParameter("test", new Product() { Price = new decimal(0.333) });
33-
context.Run("test.Price = test.Price * 2");
34-
Console.WriteLine(context.Run("test.Price").ToString());
35-
//context.Run("modified_price = test.Price * 2");
36-
//Console.WriteLine(context.GetParameter("modified_price").ToString()); //returns 0.... not good
49+
// Commit 2 - calling methods on managed objects
50+
product.DoSomething();
51+
product.DoSomething();
52+
product.DoSomethingElse();
3753
54+
// Commits 3 and 4 - using iterators
55+
for (const tax of product.GetTaxes())
56+
{{
57+
sum += tax;
58+
}}
3859
39-
try {
40-
//_context.Run("a=[]; while(true) a.push(0)");
41-
//_context.Run("function f() { f(); } f()");
60+
// Commit 5 - using JS callbacks in managed code without disposing them explicitly
61+
sum += product.GetSalesTax(p => p * 0.19);
62+
// End of scenarios
4263
43-
//while(true) {
44-
// Console.Write("> ");
45-
// var input = Console.ReadLine();
46-
// if (input == "quit")
47-
// break;
48-
// var result = _context.Run(input);
49-
// Console.WriteLine("Result is: `{0}`", result);
50-
//}
51-
} catch (Exception ex) {
52-
string s = (string)ex.Data["V8StackTrace"];
64+
sum += product.Price;
65+
}}
66+
[sum, importantProduct.Price, globalProduct.Price].toString();
67+
}}
68+
");
69+
Console.WriteLine(result);
70+
Console.WriteLine(context.GetParameter("globalProduct"));
71+
// breakpoint here - pre dispose of the context
72+
}
73+
catch (Exception ex)
74+
{
75+
var s = (string)ex.Data["V8StackTrace"]!;
5376
Console.WriteLine(s);
5477
}
55-
//Console.WriteLine(ints[1]);
5678
}
79+
GC.Collect();
80+
GC.WaitForPendingFinalizers();
81+
GC.Collect();
82+
// breakpoint here - after dispose of the context (the garbage collection was only triggered to compare the object count in the memory dump)
5783
}
5884

5985
static void FatalErrorHandler(string a, string b)
@@ -69,7 +95,7 @@ class Bozo
6995
internal Bozo(Array a) { this.a = a; }
7096
public object this[int i]
7197
{
72-
get { throw new ApplicationException("bozo"); return a.GetValue(i); }
98+
get { throw new ApplicationException("bozo"); }
7399
set { a.SetValue(value, i); }
74100
}
75101
}

Fiddling/app.config

Lines changed: 0 additions & 3 deletions
This file was deleted.

JavaScript.Net.sln

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2020
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36705.20 d17.14
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "JavaScript.Net", "Source\Noesis.Javascript\JavaScript.Net.vcxproj", "{7ECFED5E-8B33-4065-ACBF-AB1050FB0F4C}"
77
EndProject
@@ -36,28 +36,28 @@ Global
3636
{7ECFED5E-8B33-4065-ACBF-AB1050FB0F4C}.Release|x64.Build.0 = Release|x64
3737
{7ECFED5E-8B33-4065-ACBF-AB1050FB0F4C}.Release|x86.ActiveCfg = Release|Win32
3838
{7ECFED5E-8B33-4065-ACBF-AB1050FB0F4C}.Release|x86.Build.0 = Release|Win32
39-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
40-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|Any CPU.Build.0 = Debug|Any CPU
41-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|x64.ActiveCfg = Debug|Any CPU
42-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|x64.Build.0 = Debug|Any CPU
39+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|Any CPU.ActiveCfg = Debug|x64
40+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|Any CPU.Build.0 = Debug|x64
41+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|x64.ActiveCfg = Debug|x64
42+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|x64.Build.0 = Debug|x64
4343
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|x86.ActiveCfg = Debug|x86
4444
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Debug|x86.Build.0 = Debug|x86
45-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|Any CPU.ActiveCfg = Release|Any CPU
46-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|Any CPU.Build.0 = Release|Any CPU
47-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|x64.ActiveCfg = Release|Any CPU
48-
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|x64.Build.0 = Release|Any CPU
45+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|Any CPU.ActiveCfg = Release|x64
46+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|Any CPU.Build.0 = Release|x64
47+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|x64.ActiveCfg = Release|x64
48+
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|x64.Build.0 = Release|x64
4949
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|x86.ActiveCfg = Release|x86
5050
{9E0C9657-BC4C-4A25-B7DD-9C772FC5670D}.Release|x86.Build.0 = Release|x86
51-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
52-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|Any CPU.Build.0 = Debug|Any CPU
53-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|x64.ActiveCfg = Debug|Any CPU
54-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|x64.Build.0 = Debug|Any CPU
51+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|Any CPU.ActiveCfg = Debug|x64
52+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|Any CPU.Build.0 = Debug|x64
53+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|x64.ActiveCfg = Debug|x64
54+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|x64.Build.0 = Debug|x64
5555
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|x86.ActiveCfg = Debug|x86
5656
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Debug|x86.Build.0 = Debug|x86
57-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|Any CPU.ActiveCfg = Release|Any CPU
58-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|Any CPU.Build.0 = Release|Any CPU
59-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|x64.ActiveCfg = Release|Any CPU
60-
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|x64.Build.0 = Release|Any CPU
57+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|Any CPU.ActiveCfg = Release|x64
58+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|Any CPU.Build.0 = Release|x64
59+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|x64.ActiveCfg = Release|x64
60+
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|x64.Build.0 = Release|x64
6161
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|x86.ActiveCfg = Release|x86
6262
{1659A790-7DAC-4E1C-B2C8-B51AC6B0AF87}.Release|x86.Build.0 = Release|x86
6363
EndGlobalSection

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,31 @@ when you redistribute Noesis.Javascript.dll then you will get errors
4646
when loading the DLL on some users machines. (Many, but not all users
4747
will already have it.)
4848

49-
Targets: .NET Framework 4.5
49+
Targets: .NET 8
50+
51+
For legacy .NET Framework 4.7.2 support, see previous versions.
5052

5153

5254
Building from Source
5355
====================
5456

55-
Open the .sln file in Visual Studio, use Configuration Manager to switch to platform to x64, and build. I've been working using Visual Studio 2017,
56-
but 2015 will probably work too.
57+
**Requirements:**
58+
* Visual Studio 2022 (17.0+) or Visual Studio 2019 (16.4+)
59+
* .NET 8 SDK
60+
* Windows SDK 10.0 or later
61+
62+
**Steps:**
63+
64+
1. Open the .sln file in Visual Studio
65+
2. Use Configuration Manager to switch the platform to x64
66+
3. Build the solution
67+
68+
The project uses:
69+
* C++/CLI with .NET Core support (`CLRSupport=NetCore`)
70+
* .NET 8 SDK-style projects for C# code
71+
* V8 version 9.8.177.4 via NuGet packages
72+
73+
**Note:** The C++/CLI project requires Windows and Visual Studio with C++/CLI support for .NET Core. This is available in Visual Studio 2019 16.4+ and Visual Studio 2022.
5774

5875
The following warnings are expected:
5976

0 commit comments

Comments
 (0)