Private Accessor does not create when using MSBuild

My build server uses MSBuild to build my application. Our unit tests require access to some private members for testing, so we use built-in private accessors. Visual Studio has no problems with this, but when we push our code to the build server, we get an error:

MyTest.cs (96,13): errorCS0246: type or namespace name 'My_Accessor' could not be found (do you not see the link using the directive or assembly?)

Why does MSBuild ignore private accessors and how to fix it?

We use NUnit for our testing platform and CruiseControl.Net for our continuous integration server.

EDIT: As per the comment, here is some test code for the base class for the repository template class.

MockRepository mocks = new MockRepository(); IDataContextWrapper wrapper = mocks.DynamicMock<IDataContextWrapper>(); Repository_Accessor target = new Repository_Accessor(wrapper); Assert.AreEqual(wrapper, target._DataContext); 

This code simply verifies that the _DataContext member variables are set to the cheated shell. This fails when creating with MSBuild on my build server.

+4
source share
4 answers

Like Mehmet's answer, I'm afraid the only way to get this to work is to set up a visual studio. Once this was set up, msbuild started creating accessors for me. Not an ideal solution, but at least I can move on.

0
source

It seems that your assembly assembly does not create an assembly of individual accessories. As a result, you lose this information with a directive or assembly error. You can look at Create a tool for creating personal access during the build process. It indicates that

The generated assembly is also known as a private accessory. You can also create private accessors from the IDE, but you can use publicize.exe instead in Automation, scripting and scripting.

I use private accessors, as well as in some tests, and use TFS TeamBuild and MSTest. A private accessory is generated during assembly. I did not have to do anything manually.

+1
source

Are you likely that [build: InternalsVisibleTo] is installed correctly locally, but incorrectly in your build system?

(Alternatively, Assert.AreSame () might be more appropriate).

0
source

You mentioned private helpers, so I suggested that you use Reflection to expose some private members for unit testing?

If this is the case, then you should understand that peering into private members requires certain rights that must be granted. Or else, an incorrect .NET program can interfere with anything, with any builds it wants.

Are you sure that the custom Cruise Control is launched under and subsequently, the launch of runter launch and launch launch of CruiseControl is launched under the account that is provided by " ReflectionPermission " or "Full Trust" from the .NET runtime?

The / google search locations for are machine.config parameters on the build server, Cruise Control is its own web.config (not sure if it has been, since I have not used CC for a long time) and finally (and least likely ), the app.config file of both the testing and the application itself.

Otherwise, I suggest you use the Publicize tool, as @Mehmet Aras suggested.

0
source

All Articles