Browse Source

custom tools, ProtobufTool运行成功,可以在vs中把proto生成相应的cs文件

tanghai 13 years ago
parent
commit
7bff8db732

+ 0 - 12
CSharp/App/Editor/Editor.csproj

@@ -58,26 +58,14 @@
     <Prefer32Bit>false</Prefer32Bit>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
-      <HintPath>..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Expression.Interactions.dll</HintPath>
-    </Reference>
     <Reference Include="Microsoft.Practices.Prism">
       <HintPath>..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Practices.Prism.Interactivity">
-      <HintPath>..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.Interactivity.dll</HintPath>
-    </Reference>
     <Reference Include="Microsoft.Practices.Prism.MefExtensions">
       <HintPath>..\..\packages\Prism.MEFExtensions.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.MefExtensions.dll</HintPath>
     </Reference>
-    <Reference Include="Microsoft.Practices.ServiceLocation">
-      <HintPath>..\..\packages\CommonServiceLocator.1.0\lib\NET35\Microsoft.Practices.ServiceLocation.dll</HintPath>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.ComponentModel.Composition" />
-    <Reference Include="System.Windows.Interactivity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
-      <HintPath>..\..\packages\Prism.4.1.0.0\lib\NET40\System.Windows.Interactivity.dll</HintPath>
-    </Reference>
     <Reference Include="System.Xml" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xaml">

+ 30 - 0
CSharp/App/Modules/Robot/Person.pb.cs

@@ -0,0 +1,30 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+// Generated from: Person.proto
+namespace Person
+{
+  [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"Person")]
+  public partial class Person : global::ProtoBuf.IExtensible
+  {
+    public Person() {}
+    
+    private int _guid;
+    [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"guid", DataFormat = global::ProtoBuf.DataFormat.TwosComplement)]
+    public int guid
+    {
+      get { return _guid; }
+      set { _guid = value; }
+    }
+    private global::ProtoBuf.IExtension extensionObject;
+    global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
+      { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }
+  }
+  
+}

+ 1 - 1
CSharp/App/Modules/Robot/Person.proto

@@ -1,4 +1,4 @@
-message Person
+message Person
 {
 	required int32 guid = 1;
 }

+ 7 - 0
CSharp/App/Modules/Robot/Robot.csproj

@@ -54,6 +54,12 @@
     <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Person.pb.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTime>True</DesignTime>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+      <DependentUpon>Person.proto</DependentUpon>
+    </Compile>
     <Compile Include="Robot.cs" />
     <Compile Include="RobotModule.cs" />
     <Compile Include="RobotViewModel.cs" />
@@ -88,6 +94,7 @@
     <None Include="Packages.config" />
     <None Include="Person.proto">
       <Generator>ProtobufTool</Generator>
+      <LastGenOutput>Person.pb.cs</LastGenOutput>
     </None>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

BIN
CSharp/Egametang.pfx


+ 2 - 2
CSharp/Tools/ProtobufTool/Properties/AssemblyInfo.cs

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
 // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
 // 方法是按如下所示使用“*”:
 // [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.0.0.1")]
+[assembly: AssemblyFileVersion("1.0.0.1")]

+ 27 - 20
CSharp/Tools/ProtobufTool/ProtobufGenerator.cs

@@ -3,6 +3,8 @@ using System.Diagnostics;
 using System.IO;
 using System.Runtime.InteropServices;
 using Microsoft.VisualStudio.TextTemplating.VSHost;
+using EnvDTE;
+using Process = System.Diagnostics.Process;
 
 namespace ProtobufTool
 {
@@ -17,29 +19,34 @@ namespace ProtobufTool
 
 		protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
 		{
-			var processStartInfo = new ProcessStartInfo("protogen.exe")
+			using (var stream = File.Open("E:\\ProtobufTool.log", FileMode.OpenOrCreate))
+			using (var streamWriter = new StreamWriter(stream))
 			{
-				CreateNoWindow = true,
-				WindowStyle = ProcessWindowStyle.Hidden,
-				WorkingDirectory = Environment.CurrentDirectory,
-				RedirectStandardError = true,
-				RedirectStandardOutput = true
-			};
-			processStartInfo.CreateNoWindow = true;
-			processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+				streamWriter.WriteLine("input: {0}\r\n {1}", inputFileName, inputFileContent);
+				var processStartInfo = new ProcessStartInfo("protogen.exe")
+				{
+					CreateNoWindow = true,
+					WindowStyle = ProcessWindowStyle.Hidden,
+				};
 
-			var tempFile = Path.GetTempFileName();
-			string inputDir = Path.GetFullPath(inputFileName);
-			processStartInfo.Arguments = string.Format(
-				" -q -writeErrors -t: csharp -i:{0} -w:{1} -o:{2} ",
-				inputFileName, inputDir, tempFile);			
-			using(var process = Process.Start(processStartInfo))
-			{
-				process.WaitForExit();
+				var projectItem = this.GetService(typeof(ProjectItem)) as ProjectItem;
+				processStartInfo.WorkingDirectory = Path.GetDirectoryName(projectItem.ContainingProject.FullName);
+				streamWriter.WriteLine("WorkingDirectory: {0}", processStartInfo.WorkingDirectory);
+				processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
+
+				var tempFile = Path.GetTempFileName();
+				processStartInfo.Arguments = string.Format(
+						"-i:{0} -o:{1} -q -t:csharp", inputFileName, tempFile);
+				streamWriter.WriteLine("Arguments: {0}", processStartInfo.Arguments);
+				using (var process = Process.Start(processStartInfo))
+				{
+					process.WaitForExit();
+					streamWriter.WriteLine("return code: {0}", process.ExitCode);
+				}
+				byte[] bytes = File.ReadAllBytes(tempFile);
+				File.Delete(tempFile);
+				return bytes;
 			}
-			byte[] bytes = File.ReadAllBytes(tempFile);
-			File.Delete(tempFile);
-			return bytes;
 		}
     }
 }

+ 7 - 11
CSharp/Tools/ProtobufTool/ProtobufTool.csproj

@@ -37,20 +37,14 @@
     <AssemblyOriginatorKeyFile>..\..\Egametang.pfx</AssemblyOriginatorKeyFile>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+      <EmbedInteropTypes>False</EmbedInteropTypes>
+    </Reference>
     <Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-    <Reference Include="Microsoft.VisualStudio.Shell.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
     <Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-    <Reference Include="Microsoft.VisualStudio.Shell.Interop.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
-      <EmbedInteropTypes>True</EmbedInteropTypes>
-    </Reference>
     <Reference Include="Microsoft.VisualStudio.TextTemplating.VSHost.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
     <Reference Include="System" />
     <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ProtobufGenerator.cs" />
@@ -61,7 +55,9 @@
       <Link>Egametang.pfx</Link>
     </None>
     <None Include="ProtobufGenerator.reg" />
-    <None Include="register.bat" />
+    <None Include="register.bat">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </None>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>
@@ -69,7 +65,7 @@
     </PreBuildEvent>
   </PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>$(ProjectDir)\register.bat $(TargetPath) $(TargetDir)</PostBuildEvent>
+    <PostBuildEvent>$(ProjectDir)\register.bat $(TargetPath)</PostBuildEvent>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.

+ 4 - 13
CSharp/Tools/ProtobufTool/register.bat

@@ -1,15 +1,6 @@
 @echo off
-rem "%windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe" /nologo /unregister "%1"
+rem "%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /nologo /u "ProtobufTool"
+rem "%windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe" /u "ProtobufTool.dll"
 
-rem "%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /nologo /f /i "%1"
-rem "%windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe" /nologo /CodeBase "%1"
-
-goto BuildEventOK
-
-:BuildEventFailed
-echo POSTBUILDSTEP FAILED
-exit 1
-
-:BuildEventOK
-echo POSTBUILDSTEP COMPLETED OK
-exit 0
+rem "%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bin\gacutil.exe" /nologo /f /i "ProtobufTool.dll"
+rem "%windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe" /nologo /CodeBase "ProtobufTool.dll"