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

Namespace collisions with Visual Studio SDK #85

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
f921bef
renamed the namespace Microsoft.VisualStudio to Mono.VisualStudio so …
kccarter76 Jul 28, 2020
042ae23
no message
kccarter76 Jul 29, 2020
479530c
no message
kccarter76 Jul 29, 2020
41ff2db
more work on the vsix implementation
kccarter76 Jul 29, 2020
d992902
merged teh vsix changes into the mono.texttemplating project.
kccarter76 Jul 29, 2020
7fcffc6
removed the vsix library project file
kccarter76 Jul 29, 2020
c83c292
removed another file - yagni
kccarter76 Jul 29, 2020
a493fb4
mispelled a namespace
kccarter76 Jul 29, 2020
9ad0858
update to ensure that the service that is built works with what has b…
kccarter76 Jul 29, 2020
e7e7a3b
re-initialize the error callback
kccarter76 Jul 30, 2020
4aebef7
moved the Engine class back into the microsoft namespace with the obs…
kccarter76 Jul 30, 2020
3a8356e
rename InputFile to TemplateFile
kccarter76 Jul 30, 2020
4e3bc72
update get settings to request from the host as well if not in the te…
kccarter76 Jul 30, 2020
b5266bd
no message
kccarter76 Jul 31, 2020
217db5b
Merge branch 'pullrequest/issue-84'
kccarter76 Jul 31, 2020
929b52f
added a means by which a text writer for the log can be set.
kccarter76 Jul 31, 2020
c289524
added a cancelation token to the template settings
kccarter76 Jul 31, 2020
be0d394
if canceled do not await process that was never started
kccarter76 Jul 31, 2020
78b2854
update process to be asynchronous on writing messages out
kccarter76 Jul 31, 2020
a72403c
more code that was not written correctly for asynchronous work
kccarter76 Jul 31, 2020
ba6bd93
few more
kccarter76 Jul 31, 2020
3344933
update references
kccarter76 Jul 31, 2020
e3c9227
no message
kccarter76 Jul 31, 2020
0ddbca4
trying to get this process to yield to the main thread
kccarter76 Jul 31, 2020
30aaed7
no message
kccarter76 Jul 31, 2020
fc496a8
try writing lines again
kccarter76 Jul 31, 2020
1692d0f
yagni
kccarter76 Jul 31, 2020
580d453
3rd time is a charm
kccarter76 Jul 31, 2020
ea8e698
no message
kccarter76 Jul 31, 2020
f258229
testing the logging to string builder async
kccarter76 Jul 31, 2020
0011528
roll back to before, the log writer for VS will convert Write synchro…
kccarter76 Jul 31, 2020
53fa354
clean up around extra line
kccarter76 Jul 31, 2020
09ec388
added a delimeter for the error logging
kccarter76 Jul 31, 2020
87026b2
no message
kccarter76 Jul 31, 2020
92960e0
added the ability to configure the runtime for any template runner th…
kccarter76 Jul 31, 2020
5d5c176
System.Private.CoreLib is a bad image
kccarter76 Aug 1, 2020
9d42235
Revert "System.Private.CoreLib is a bad image"
kccarter76 Aug 1, 2020
2a4b599
best effort to detect encoding
kccarter76 Aug 1, 2020
b8a7f47
renamed the debug interfaces to process interfaces, the new approach …
kccarter76 Aug 1, 2020
9c8e762
will work on makeing the process work asynchronously with visual studio
kccarter76 Aug 1, 2020
2431576
temp directory was not being cleaned up and was spamming folder creation
kccarter76 Aug 1, 2020
203095d
address code cop warnings
kccarter76 Aug 1, 2020
9db4f27
no message
kccarter76 Aug 1, 2020
0803d38
no message
kccarter76 Aug 1, 2020
d43c621
when debugging I want the temp files to stick around
kccarter76 Aug 1, 2020
d4cd16d
#87
kccarter76 Aug 1, 2020
2a18adf
no message
kccarter76 Aug 1, 2020
247402a
#87
kccarter76 Aug 1, 2020
a84ba73
#87
kccarter76 Aug 1, 2020
6a58f71
no message
kccarter76 Aug 1, 2020
faf14e4
#87 turns out building template in .net framework to run in the net c…
kccarter76 Aug 1, 2020
463ce19
no message
kccarter76 Aug 1, 2020
b7af9bc
no message
kccarter76 Aug 1, 2020
57e4e52
no message
kccarter76 Aug 2, 2020
b2778d2
no message
kccarter76 Aug 2, 2020
00f3f4b
no message
kccarter76 Aug 2, 2020
982e2e5
these two items will have to cross domain process boundaries
kccarter76 Aug 3, 2020
585511d
Merge branch 'master' into pullrequest/issue-84
kccarter76 Aug 3, 2020
0a2efc8
#88 apply the patch for Parameter properties should be static
kccarter76 Aug 12, 2020
6d10ef8
additional tests to make sure the parameter was set
kccarter76 Aug 12, 2020
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
10 changes: 9 additions & 1 deletion Mono.TextTemplating.Roslyn/Mono.TextTemplating.Roslyn.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,23 @@ To enable the in-process C# compiler, use the TemplatingEngine.UseInProcessCompi
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Mono.TextTemplating\Mono.TextTemplating.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.2.31" />
</ItemGroup>
</Project>
18 changes: 10 additions & 8 deletions Mono.TextTemplating.Tests/DummyHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using System;
using System.Collections.Generic;
using System.CodeDom.Compiler;
using Microsoft.VisualStudio.TextTemplating;
using Mono.VisualStudio.TextTemplating;

namespace Mono.TextTemplating.Tests
{
Expand All @@ -37,11 +37,11 @@ public class DummyHost : ITextTemplatingEngineHost
public readonly Dictionary<string, string> Locations = new Dictionary<string, string> ();
public readonly Dictionary<string, string> Contents = new Dictionary<string, string> ();
public readonly Dictionary<string, object> HostOptions = new Dictionary<string, object> ();
List<string> standardAssemblyReferences = new List<string> ();
List<string> standardAssemblyReferences = new List<string> (new[] { typeof(TemplatingEngine).Assembly.Location });
List<string> standardImports = new List<string> ();
public readonly CompilerErrorCollection Errors = new CompilerErrorCollection ();
public readonly Dictionary<string, Type> DirectiveProcessors = new Dictionary<string, Type> ();

public readonly Dictionary<string, string> Parameters = new Dictionary<string, string> ();
public virtual object GetHostOption (string optionName)
{
object o;
Expand All @@ -68,7 +68,7 @@ public virtual AppDomain ProvideTemplatingAppDomain (string content)

public virtual string ResolveAssemblyReference (string assemblyReference)
{
throw new System.NotImplementedException();
return assemblyReference;
}

public virtual Type ResolveDirectiveProcessor (string processorName)
Expand All @@ -80,22 +80,24 @@ public virtual Type ResolveDirectiveProcessor (string processorName)

public virtual string ResolveParameterValue (string directiveId, string processorName, string parameterName)
{
throw new System.NotImplementedException();
return Parameters[parameterName];
}

public virtual string ResolvePath (string path)
{
throw new System.NotImplementedException();
}


string extension;

public virtual void SetFileExtension (string extension)
{
throw new System.NotImplementedException();
this.extension = extension;
}

public virtual void SetOutputEncoding (System.Text.Encoding encoding, bool fromOutputDirective)
{
throw new System.NotImplementedException();

}

public virtual IList<string> StandardAssemblyReferences {
Expand Down
81 changes: 76 additions & 5 deletions Mono.TextTemplating.Tests/GenerationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Microsoft.VisualStudio.TextTemplating;
using Mono.VisualStudio.TextTemplating;
using System.Linq;
using System.CodeDom.Compiler;
using System.Reflection;

namespace Mono.TextTemplating.Tests
{
Expand All @@ -48,6 +49,60 @@ public void TemplateGeneratorTest ()
Assert.IsNull (gen.Errors.OfType<CompilerError> ().FirstOrDefault (), "ProcessTemplate");
}

[Test]
public void GenerateStaticPropertyForParameter ()
{
var engine = new TemplatingEngine ();

var host = new DummyHost ();

var output = engine.PreprocessTemplate (T4ParameterSample, host, "ParameterTestClass", "Testing", out string language, out string[] references);

foreach (CompilerError error in host.Errors) {
Console.Error.WriteLine (error.ErrorText);
}

Assert.IsTrue (output.Contains ("public static string TestParameter"));

Console.Out.WriteLine (output);
}

[Test]
[TestCase("some nonsense value")]
public void GenerateStaticPropertyForParameterCanInitilialize (string value)
{
var engine = new TemplatingEngine ();

var host = new DummyHost () {
TemplateFile = "test.tt"
};

host.Parameters.Add ("TestParameter", value);


var tt = engine.CompileTemplate (T4ParameterSample, host);

foreach (CompilerError error in host.Errors) {
Console.Error.WriteLine (error.ErrorText);
}

Type ttType = tt.textTransformation?.GetType ();

Assert.IsNotNull (ttType);

var initMethod = ttType.GetMethod ("Initialize");
var testAssignment = ttType.GetMethod ("TestAssignment");
var parameter = ttType.GetProperty ("TestParameter", BindingFlags.Public | BindingFlags.Static);

initMethod.Invoke (tt.textTransformation, null);

if (testAssignment.Invoke(tt.textTransformation, null) is bool success) {
Assert.IsTrue (success);
}

Assert.AreEqual (value, parameter.GetValue (null));
}

[Test]
public void ImportReferencesTest ()
{
Expand Down Expand Up @@ -105,6 +160,8 @@ public void GenerateWindowsNewlines ()
Generate (WinInput, WinOutput, "\r\n");
}



[Test]
public void DefaultLanguage ()
{
Expand All @@ -121,7 +178,7 @@ public void DefaultLanguage ()
void Generate (string input, string expectedOutput, string newline)
{
var host = new DummyHost ();
string nameSpaceName = "Microsoft.VisualStudio.TextTemplating4f504ca0";
string nameSpaceName = "Mono.VisualStudio.TextTemplating4f504ca0";
string code = GenerateCode (host, input, nameSpaceName, newline);
Assert.AreEqual (0, host.Errors.Count);

Expand Down Expand Up @@ -164,14 +221,28 @@ string GenerateCode (ITextTemplatingEngineHost host, string content, string name

#endregion

#region input strings
public const string T4ParameterSample =
@"<#@ template hostspecific=""true"" language=""C#"" #>
<#@ output extension="".cs"" #>
<#@ parameter type=""System.String"" name=""TestParameter"" #>
<#@ import namespace=""System"" #>
using System;
<#+
public bool TestAssignment() {
return !string.IsNullOrEmpty(TestParameter);
}
#>";
#endregion

#region Expected output strings

public static string OutputSample1 =
@"
namespace Microsoft.VisualStudio.TextTemplating4f504ca0 {
namespace Mono.VisualStudio.TextTemplating4f504ca0 {


public partial class GeneratedTextTransformation : global::Microsoft.VisualStudio.TextTemplating.TextTransformation {
public partial class GeneratedTextTransformation : global::Mono.VisualStudio.TextTemplating.TextTransformation {


#line 9 """"
Expand Down Expand Up @@ -205,7 +276,7 @@ public override string TransformText() {
#line hidden

#line 7 """"
this.Write(global::Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture( bar ));
this.Write(global::Mono.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture( bar ));

#line default
#line hidden
Expand Down
11 changes: 9 additions & 2 deletions Mono.TextTemplating.Tests/Mono.TextTemplating.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
<ItemGroup>
<ProjectReference Include="..\Mono.TextTemplating.Roslyn\Mono.TextTemplating.Roslyn.csproj" />
<ProjectReference Include="..\Mono.TextTemplating\Mono.TextTemplating.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="Nerdbank.GitVersioning" Version="3.2.31" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Microsoft.VisualStudio.TextTemplating;
using Mono.VisualStudio.TextTemplating;

namespace Mono.TextTemplating.Tests
{
Expand Down
4 changes: 2 additions & 2 deletions Mono.TextTemplating.Tests/TextTemplatingSessionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
// TextTemplatingSessionTests.cs
//
// Author:
Expand Down Expand Up @@ -26,7 +26,7 @@

using System;
using System.Reflection;
using Microsoft.VisualStudio.TextTemplating;
using Mono.VisualStudio.TextTemplating;
using NUnit.Framework;

namespace Mono.TextTemplating.Tests
Expand Down
17 changes: 9 additions & 8 deletions Mono.TextTemplating.sln
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.TextTemplating", "Mono.TextTemplating\Mono.TextTemplating.csproj", "{A2364D6A-00EF-417C-80A6-815726C70032}"
# Visual Studio Version 16
VisualStudioVersion = 16.0.30320.27
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.TextTemplating", "Mono.TextTemplating\Mono.TextTemplating.csproj", "{A2364D6A-00EF-417C-80A6-815726C70032}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.TextTemplating.Tests", "Mono.TextTemplating.Tests\Mono.TextTemplating.Tests.csproj", "{CB590106-8331-4CBE-8131-B154E7BF79E1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.TextTemplating.Tests", "Mono.TextTemplating.Tests\Mono.TextTemplating.Tests.csproj", "{CB590106-8331-4CBE-8131-B154E7BF79E1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextTransform", "TextTransform\TextTransform.csproj", "{D1D35409-C814-47F6-B038-B9B5BF0FE490}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextTransform", "TextTransform\TextTransform.csproj", "{D1D35409-C814-47F6-B038-B9B5BF0FE490}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EEE624A1-0ED3-4D57-96B4-5D1B22E72697}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Directory.Build.props = Directory.Build.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-t4", "dotnet-t4\dotnet-t4.csproj", "{6AA924D8-7119-4593-9B56-11D17AC3578E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-t4", "dotnet-t4\dotnet-t4.csproj", "{6AA924D8-7119-4593-9B56-11D17AC3578E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-t4-project-tool", "dotnet-t4-project-tool\dotnet-t4-project-tool.csproj", "{114B7AEF-61DA-453A-9A84-6DDEA13460B7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-t4-project-tool", "dotnet-t4-project-tool\dotnet-t4-project-tool.csproj", "{114B7AEF-61DA-453A-9A84-6DDEA13460B7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.TextTemplating.Roslyn", "Mono.TextTemplating.Roslyn\Mono.TextTemplating.Roslyn.csproj", "{8DB780A9-27C1-44B4-860F-50C4419FD349}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.TextTemplating.Roslyn", "Mono.TextTemplating.Roslyn\Mono.TextTemplating.Roslyn.csproj", "{8DB780A9-27C1-44B4-860F-50C4419FD349}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@

using System;
using Mono.TextTemplating;
using Mono.VisualStudio.TextTemplating;

namespace Microsoft.VisualStudio.TextTemplating
{
[Obsolete ("Use Mono.TextTemplating.TemplatingEngine directly")]
public class Engine : ITextTemplatingEngine
[Obsolete ("Use Mono.TextTemplating.TemplatingEngine directly", true)]
public class Engine
: ITextTemplatingEngine
{
TemplatingEngine engine = new TemplatingEngine ();

Expand All @@ -44,7 +46,7 @@ public string PreprocessTemplate (string content, ITextTemplatingEngineHost host
{
return engine.PreprocessTemplate (content, host, className, classNamespace, out language, out references);
}

public const string CacheAssembliesOptionString = "CacheAssemblies";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ IEnumerable<string> GetImplicitReferences ()
{
yield return "mscorlib.dll";
yield return "netstandard.dll";

if (runtime.Kind == RuntimeKind.NetCore) {
yield return "System.Runtime.dll";
//because we're referencing the impl not the ref asms, we end up
Expand Down
Loading