Вопрос

I have a C# web service project. I created a client that creates and manages the connection to the service. We have an older PC product that is written in C++ and they need to have an interface to make calls to the service. I created some calls on the client for them and made new objects that are COM visible to pass the data around. I then check the box in the project settings that says “Register for COM interop”. This all seems to build and work locally (I run visual studio as an admin). But when I check in on my TFS server the build fails stating: Cannot register assembly "MyClient.dll" - access denied. Please make sure you're running the application as administrator. Access to the registry key 'HKEY_CLASSES_ROOT\MyClient.MyClass' is denied. Is there a way to elevate my token on the build machine or some other way to resolve this?

Это было полезно?

Решение 2

I figured out a way for this to work! If you look at the XML in your project you see a node that looks like this:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==  'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>
     <DebugType>full</DebugType>
     <Optimize>false</Optimize>
     <OutputPath>bin\Debug\</OutputPath>
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
     <PlatformTarget>x86</PlatformTarget>
     <UseVSHostingProcess>false</UseVSHostingProcess>
     <RegisterForComInterop>true</RegisterForComInterop>    
</PropertyGroup>

The problem here is of course the line that tells the project to register for com interop. I also see a similar definition for the release configuration. I can solve the issue by removing the line or, through the UI, unchecking the box but I have other people on the project that need to get the code and it would be better if the version of the project in source control just worked for them. the answer is to uncheck the register interop box on the release definition but keep it on the debug definition and then alter the build TFS definition to only build for release. That way, my co-workers can have the com object and the build server doesn’t complain.

Другие советы

You need to pass below value to MSBuild using the MSBuild Arguments option in process parameter of your build definition.

/p:RegisterForComInterop=false

Your TFS build agent is probably running under a service account so that is the account that needs the elevated privileges. You need to add the service account to the administrators group on your build server(s).

However your TFS Admin might not want to do that. Even if giving the account extra privileges isn't a problem, they might have an issue with your build doing "stuff" to the registry.

You can call COM components from c++ without needing to register them

This article on Registration Free COM goes in to more detail

I found this symptom as well but it was because windows update publicy according to the company's policy and followed by JonesCola in a recommendation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top