Unsafe code

  • Thread starter Thread starter Andy
  • Start date Start date
A

Andy

Hi,

I have a question... I have some code which has an unsafe block in it.

In VS2008 (Framework 3.5), i go to the project property and check the
box that allows unsafe blocks. The code compiles fine.

On my build server though, things are not happy. The error seems to
be that /unsafe needs to be set as a command line option, even though
MSBuild is being used.

Shouldn't MSbuild be picking up the <AllowUnsafeBlocks /> element in
the csproj file?

Thanks
Andy
 
Andy said:
Hi,

I have a question... I have some code which has an unsafe block in it.

In VS2008 (Framework 3.5), i go to the project property and check the
box that allows unsafe blocks. The code compiles fine.

On my build server though, things are not happy. The error seems to
be that /unsafe needs to be set as a command line option, even though
MSBuild is being used.

Shouldn't MSbuild be picking up the <AllowUnsafeBlocks /> element in
the csproj file?

Thanks
Andy

Hi Andy,

It should and it does for me. What kind of error do you get? If you add
AllowUnsafeBlocks=true to the command does it compile then?
 
I get an error saying /unsafe has to be specified on the command
line...

If I add /:AllowUnsafeBlocks=true to the command line for msbuild, it
builds it. That's how I've worked around this, but because all my
builds use the same build command, they all now have that switch,
which isn't ideal to me.
 
Andy said:
I get an error saying /unsafe has to be specified on the command
line...

If I add /:AllowUnsafeBlocks=true to the command line for msbuild, it
builds it. That's how I've worked around this, but because all my
builds use the same build command, they all now have that switch,
which isn't ideal to me.

Hi Andy,

Do you specify which platform and configuration msbuild should use on your
build machine? I believe MSBuild defaults to AnyCPU and Debug and if your
project files don't have the <AllowUnsafeBlock/> node set in this
configuration it will complain about any unsafe blocks.
 
Actually that raises a good point; I keep my configuration in Debug,
while my build server sets it to Release. I'll make sure to set this
for all configurations in the project file and see what happens.
 
HI,

Yes, that was it. I went to the Configuration settings and choose All
Configurations, and check Allow Unsafe code there, and it builds
correctly now.

Thanks for your help!
Andy
 
Back
Top