Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit68da61f

Browse files
enricosadalatkin
authored andcommitted
fix add file reference (com dll)
lcid is an integerfix typelib registry path, the lcid part is the hexadecimal string representation of the lcid valueadded exception on failed add referencefix nre on if registry key not foundfixesdotnet#278closesdotnet#281commit64185d2Author: enricosada <enrico@sada.io>Date: Tue Mar 3 21:45:40 2015 +0100 add testcommitc4fb65dAuthor: enricosada <enrico@sada.io>Date: Fri Feb 27 19:31:29 2015 +0100 remove unused try/catchcommit4a05993Author: enricosada <enrico@sada.io>Date: Fri Feb 27 18:47:03 2015 +0100 fix add file reference (com dll) lcid is an integer fix typelib registry path, the lcid part is the hexadecimal string representation of the lcid value added exception on failed add reference fix nre on if registry key not foundfixdotnet#278
1 parent62fccd8 commit68da61f

File tree

5 files changed

+86
-23
lines changed

5 files changed

+86
-23
lines changed

‎vsintegration/src/unittests/Tests.ProjectSystem.References.fs‎

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ open UnitTests.TestLib.ProjectSystem
1616
openMicrosoft.VisualStudio.FSharp.ProjectSystem
1717
openMicrosoft.VisualStudio.Shell.Interop
1818
openMicrosoft.Win32
19+
openSystem.Xml.Linq
1920

2021
[<TestFixture>]
2122
typeReferences()=
@@ -618,4 +619,60 @@ type References() =
618619
// look for the new property inside of the project file
619620
letcontents= File.ReadAllText(newProjFileName)
620621
AssertContains contents newPropVal
621-
)
622+
)
623+
624+
625+
[<Test>]
626+
memberpublicthis.``AddReference.COM``()=
627+
DoWithTempFile"Test.fsproj"(fun projFile->
628+
File.AppendAllText(projFile, TheTests.SimpleFsprojText([],[],""))
629+
use project= TheTests.CreateProject(projFile)
630+
631+
letguid= Guid("50a7e9b0-70ef-11d1-b75a-00a0c90564fe")
632+
633+
letselectorData= VSCOMPONENTSELECTORDATA(
634+
``type``= VSCOMPONENTTYPE.VSCOMPONENTTYPE_Com2,
635+
guidTypeLibrary= guid,
636+
wTypeLibraryMinorVersion=0us,
637+
wTypeLibraryMajorVersion=1us,
638+
bstrTitle="Microsoft Shell Controls And Automation")
639+
letrefContainer= GetReferenceContainerNode(project)
640+
641+
letcomReference= refContainer.AddReferenceFromSelectorData(selectorData)
642+
643+
// check reference node properties
644+
Assert.IsNotNull comReference
645+
Assert.IsInstanceOf(typeof<ComReferenceNode>, comReference)
646+
letcomRef= comReference:?> ComReferenceNode
647+
Assert.AreEqual(1, comRef.MajorVersionNumber)
648+
Assert.AreEqual(0, comRef.MinorVersionNumber)
649+
Assert.AreEqual(guid, comRef.TypeGuid)
650+
Assert.AreEqual("Microsoft Shell Controls And Automation", comRef.Caption)
651+
letsysDirectory= Environment.GetFolderPath(Environment.SpecialFolder.SystemX86)
652+
StringAssert.AreEqualIgnoringCase(Path.Combine(sysDirectory,"shell32.dll"), comRef.InstalledFilePath)
653+
654+
// check node exists under references
655+
letl=new List<ComReferenceNode>()
656+
project.FindNodesOfType(l)
657+
658+
Assert.AreEqual(1, l.Count)
659+
letreferenceNode= l.[0]
660+
Assert.AreSame(comRef, referenceNode)
661+
662+
// check saved msbuild item
663+
SaveProject(project)
664+
letfsproj= XDocument.Load(project.FileName)
665+
printfn"%O" fsproj
666+
letxn s= fsproj.Root.GetDefaultNamespace().GetName(s)
667+
letcomReferencesXml= fsproj.Descendants(xn"COMReference")|> Seq.toList
668+
669+
Assert.AreEqual(1, comReferencesXml|> List.length)
670+
671+
letcomRefXml= comReferencesXml|> List.head
672+
673+
Assert.AreEqual("Microsoft Shell Controls And Automation", comRefXml.Attribute(XName.Get("Include")).Value)
674+
Assert.AreEqual(guid, Guid(comRefXml.Element(xn"Guid").Value))
675+
Assert.AreEqual("1", comRefXml.Element(xn"VersionMajor").Value)
676+
Assert.AreEqual("0", comRefXml.Element(xn"VersionMinor").Value)
677+
Assert.AreEqual("0", comRefXml.Element(xn"Lcid").Value)
678+
)

‎vsintegration/src/vs/FsPkgs/FSharp.Project/Common.Source.CSharp/Project/Automation/VSProject/OAComReference.cs‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,8 @@ public override string Culture
2424
{
2525
get
2626
{
27-
intlocale=0;
28-
try
29-
{
30-
locale=int.Parse(BaseReferenceNode.LCID,CultureInfo.InvariantCulture);
31-
}
32-
catch(System.FormatException)
33-
{
34-
// Do Nothing
35-
}
27+
varlocale=BaseReferenceNode.LCID;
28+
3629
if(0==locale)
3730
{
3831
returnstring.Empty;

‎vsintegration/src/vs/FsPkgs/FSharp.Project/Common.Source.CSharp/Project/ComReferenceNode.cs‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ [ DllImport( "oleaut32.dll", CharSet = CharSet.Unicode, PreserveSig = false )]
4242
privatestringinstalledFilePath;
4343
privatestringminorVersionNumber;
4444
privatestringmajorVersionNumber;
45-
privatestringlcid;
45+
privatereadonlyintlcid;
4646
#endregion
4747

4848
#region properties
@@ -76,7 +76,7 @@ public string InstalledFilePath
7676
}
7777

7878
[SuppressMessage("Microsoft.Naming","CA1709:IdentifiersShouldBeCasedCorrectly",MessageId="LCID")]
79-
publicstringLCID
79+
publicintLCID
8080
{
8181
get{returnlcid;}
8282
}
@@ -133,7 +133,7 @@ internal ComReferenceNode(ProjectNode root, ProjectElement element)
133133

134134
this.majorVersionNumber=this.ItemNode.GetMetadata(ProjectFileConstants.VersionMajor);
135135
this.minorVersionNumber=this.ItemNode.GetMetadata(ProjectFileConstants.VersionMinor);
136-
this.lcid=this.ItemNode.GetMetadata(ProjectFileConstants.Lcid);
136+
this.lcid=int.Parse(this.ItemNode.GetMetadata(ProjectFileConstants.Lcid));
137137
this.SetProjectItemsThatRelyOnReferencesToBeResolved(false);
138138
this.SetInstalledFilePath();
139139
}
@@ -161,14 +161,15 @@ internal ComReferenceNode(ProjectNode root, VSCOMPONENTSELECTORDATA selectorData
161161
this.typeGuid=selectorData.guidTypeLibrary;
162162
this.majorVersionNumber=selectorData.wTypeLibraryMajorVersion.ToString(CultureInfo.InvariantCulture);
163163
this.minorVersionNumber=selectorData.wTypeLibraryMinorVersion.ToString(CultureInfo.InvariantCulture);
164-
this.lcid=selectorData.lcidTypeLibrary.ToString(CultureInfo.InvariantCulture);
164+
this.lcid=(int)selectorData.lcidTypeLibrary;
165165

166166
// Check to see if the COM object actually exists.
167167
this.SetInstalledFilePath();
168168
// If the value cannot be set throw.
169169
if(String.IsNullOrEmpty(this.installedFilePath))
170170
{
171-
thrownewArgumentException();
171+
varmessage=string.Format(SR.GetString(SR.ReferenceCouldNotBeAdded,CultureInfo.CurrentUICulture),selectorData.bstrTitle);
172+
thrownewInvalidOperationException(message);
172173
}
173174
}
174175

@@ -195,14 +196,15 @@ internal ComReferenceNode(ProjectNode root, string filePath)
195196
this.typeGuid=typeAttr.guid;
196197
this.majorVersionNumber=typeAttr.wMajorVerNum.ToString(CultureInfo.InvariantCulture);
197198
this.minorVersionNumber=typeAttr.wMinorVerNum.ToString(CultureInfo.InvariantCulture);
198-
this.lcid=typeAttr.lcid.ToString(CultureInfo.InvariantCulture);
199+
this.lcid=typeAttr.lcid;
199200

200201
// Check to see if the COM object actually exists.
201202
this.SetInstalledFilePath();
202203
// If the value cannot be set throw.
203204
if(String.IsNullOrEmpty(this.installedFilePath))
204205
{
205-
thrownewArgumentException();
206+
varmessage=string.Format(SR.GetString(SR.ReferenceCouldNotBeAdded,CultureInfo.CurrentUICulture),filePath);
207+
thrownewInvalidOperationException(message);
206208
}
207209
}
208210
finally
@@ -281,21 +283,20 @@ internal ComReferenceNode(ProjectNode root, string filePath)
281283
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization","CA1308:NormalizeStringsToUppercase")]
282284
privateProjectElementGetProjectElementBasedOnInputFromComponentSelectorData()
283285
{
284-
285286
ProjectElementelement=newProjectElement(this.ProjectMgr,this.typeName,ProjectFileConstants.COMReference);
286287

287288
// Set the basic information regarding this COM component
288289
element.SetMetadata(ProjectFileConstants.Guid,this.typeGuid.ToString("B"));
289290
element.SetMetadata(ProjectFileConstants.VersionMajor,this.majorVersionNumber);
290291
element.SetMetadata(ProjectFileConstants.VersionMinor,this.minorVersionNumber);
291-
element.SetMetadata(ProjectFileConstants.Lcid,this.lcid);
292+
element.SetMetadata(ProjectFileConstants.Lcid,this.lcid.ToString());
292293
element.SetMetadata(ProjectFileConstants.Isolated,false.ToString());
293294

294295
// See if a PIA exist for this component
295296
TypeLibConvertertypelib=newTypeLibConverter();
296297
stringassemblyName;
297298
stringassemblyCodeBase;
298-
if(typelib.GetPrimaryInteropAssembly(this.typeGuid,Int32.Parse(this.majorVersionNumber,CultureInfo.InvariantCulture),Int32.Parse(this.minorVersionNumber,CultureInfo.InvariantCulture),Int32.Parse(this.lcid,CultureInfo.InvariantCulture),outassemblyName,outassemblyCodeBase))
299+
if(typelib.GetPrimaryInteropAssembly(this.typeGuid,Int32.Parse(this.majorVersionNumber,CultureInfo.InvariantCulture),Int32.Parse(this.minorVersionNumber,CultureInfo.InvariantCulture),this.lcid,outassemblyName,outassemblyCodeBase))
299300
{
300301
element.SetMetadata(ProjectFileConstants.WrapperTool,WrapperToolAttributeValue.Primary.ToString().ToLowerInvariant());
301302
}
@@ -325,7 +326,7 @@ private void SetProjectItemsThatRelyOnReferencesToBeResolved(bool renameItemNode
325326
if(String.Compare(MSBuildItem.GetMetadataValue(reference,ProjectFileConstants.Guid),this.typeGuid.ToString("B"),StringComparison.OrdinalIgnoreCase)==0
326327
&&String.Compare(MSBuildItem.GetMetadataValue(reference,ProjectFileConstants.VersionMajor),this.majorVersionNumber,StringComparison.OrdinalIgnoreCase)==0
327328
&&String.Compare(MSBuildItem.GetMetadataValue(reference,ProjectFileConstants.VersionMinor),this.minorVersionNumber,StringComparison.OrdinalIgnoreCase)==0
328-
&&String.Compare(MSBuildItem.GetMetadataValue(reference,ProjectFileConstants.Lcid),this.lcid,StringComparison.OrdinalIgnoreCase)==0)
329+
&&String.Compare(MSBuildItem.GetMetadataValue(reference,ProjectFileConstants.Lcid),this.lcid.ToString(),StringComparison.OrdinalIgnoreCase)==0)
329330
{
330331
stringname=MSBuildItem.GetEvaluatedInclude(reference);
331332
if(Path.IsPathRooted(name))
@@ -365,9 +366,16 @@ private void SetInstalledFilePath()
365366
this.typeName=typeLib.GetValue(string.Empty)asstring;
366367
}
367368
// Now get the path to the file that contains this type library.
368-
using(RegistryKeyinstallKey=typeLib.OpenSubKey(string.Format(CultureInfo.InvariantCulture,@"{0}\win32",this.lcid)))
369+
370+
// lcid
371+
// The hexadecimal string representation of the locale identifier (LCID).
372+
// It is one to four hexadecimal digits with no 0x prefix and no leading zeros.
373+
using(RegistryKeyinstallKey=typeLib.OpenSubKey(string.Format(CultureInfo.InvariantCulture,@"{0:X}\win32",this.lcid)))
369374
{
370-
this.installedFilePath=installKey.GetValue(String.Empty)asString;
375+
if(installKey!=null)
376+
{
377+
this.installedFilePath=installKey.GetValue(String.Empty)asString;
378+
}
371379
}
372380
}
373381
}

‎vsintegration/src/vs/FsPkgs/FSharp.Project/Common.Source.CSharp/Project/Microsoft.VisualStudio.Package.Project.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ protected override string GetLocalizedString(string value)
153153
/*internal, but public for FSharp.Project.dll*/publicconststringProjectProperties="ProjectProperties";
154154
/*internal, but public for FSharp.Project.dll*/publicconststringQuiet="Quiet";
155155
/*internal, but public for FSharp.Project.dll*/publicconststringQueryReloadNestedProject="QueryReloadNestedProject";
156+
/*internal, but public for FSharp.Project.dll*/publicconststringReferenceCouldNotBeAdded="ReferenceCouldNotBeAdded";
156157
/*internal, but public for FSharp.Project.dll*/publicconststringReferenceAlreadyExists="ReferenceAlreadyExists";
157158
/*internal, but public for FSharp.Project.dll*/publicconststringReferenceWithAssemblyNameAlreadyExists="ReferenceWithAssemblyNameAlreadyExists";
158159
/*internal, but public for FSharp.Project.dll*/publicconststringReferencesNodeName="ReferencesNodeName";

‎vsintegration/src/vs/FsPkgs/FSharp.Project/Common.Source.CSharp/Project/Microsoft.VisualStudio.Package.Project.resx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@
125125
<value>Advanced</value>
126126
<comment>Project Property Page Caption</comment>
127127
</data>
128+
<dataname="ReferenceCouldNotBeAdded"xml:space="preserve">
129+
<value>A reference to '{0}' could not be added.</value>
130+
<comment>ReferenceCouldNotBeAdded error message</comment>
131+
</data>
128132
<dataname="ReferenceAlreadyExists"xml:space="preserve">
129133
<value>A reference to '{0}' could not be added. A reference to the component '{1}' already exists in the project.</value>
130134
<comment>ReferenceAlreadyExists error message</comment>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp