Discussion:
Specifying args for csc.exe
(too old to reply)
ElChino
2016-01-12 12:58:52 UTC
Permalink
Hello group.

I'm a complete neophyte when it comes to .Net/C#, but
have the need to build an old project from a .csproj
file.

My question is how to pass arguments like '/unsafe+' to
csc.exe in such a .csproj file?

I tried using a build.bat file with stuff like:

setlocal
set EXTRA_DIRS=..\src;..\src\Common
set UseEnv=True
set LIB=%LIB%;%EXTRA_DIRS%
msbuild -nologo -property:Configuration=Release the-project.csproj

The build seems to pickup those %EXTRA_DIRS%; from the MSbuild.log:
Task "Csc"
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
/lib:..\src,..\src\Common /nowarn:1701,1702

But how do I pass in '/unsafe+' in a similar manner?

BTW. Is there another env-var besides %LIB that is more suited?
Arne Vajhøj
2016-01-22 01:33:07 UTC
Permalink
Post by ElChino
I'm a complete neophyte when it comes to .Net/C#, but
have the need to build an old project from a .csproj
file.
My question is how to pass arguments like '/unsafe+' to
csc.exe in such a .csproj file?
setlocal
set EXTRA_DIRS=..\src;..\src\Common
set UseEnv=True
set LIB=%LIB%;%EXTRA_DIRS%
msbuild -nologo -property:Configuration=Release the-project.csproj
Task "Csc"
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
/lib:..\src,..\src\Common /nowarn:1701,1702
But how do I pass in '/unsafe+' in a similar manner?
BTW. Is there another env-var besides %LIB that is more suited?
Trying to hand customize a generated csproj file is not easy because
it is generated by software to be read by software not for humans.

I can see 2 approaches moving forward:
1) open the project in an IDE, change the config as you want and save
the config
2) create you complete own build script from scratch

Unless the project is very complex then #2 should be rather simple.

You can choose between:
- BAT/CMD file
- create a csproj from scratch [generated csproj files are complex, but
it is actually very easy to write one yourself!]

Arne
Anton Shepelev
2016-01-26 17:19:28 UTC
Permalink
Trying to hand customize a generated csproj file
is not easy because it is generated by software to
be read by software not for humans.
generated csproj files are complex, but it is ac-
tually very easy to write one yourself!
In my experience, it is not so difficult to modify a
generated .csproj . The major problem is that it
contains the scalar product of Platform-Configura-
tion conditions, and often more than that. The
first thing to do is to remove *all* tags with such
conditions, e.g.:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
</PropertyGroup>

and insert, or better include, a simplified version,
e.g.:

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Platform)' == 'AnyCPU'"></PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'x86'"></PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'x64'"></PropertyGroup>
<PropertyGroup>
<PlatformTarget>$(Platform)</PlatformTarget>
<OutputPath>bin\$(Configuration)\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
</PropertyGroup>
</Project>

upon which the file becomes small, clean, and main-
tainable.
--
() ascii ribbon campaign - against html e-mail
/\ http://preview.tinyurl.com/qcy6mjc [archived]
Arne Vajhøj
2016-01-28 02:24:19 UTC
Permalink
Post by Anton Shepelev
Trying to hand customize a generated csproj file
is not easy because it is generated by software to
be read by software not for humans.
generated csproj files are complex, but it is ac-
tually very easy to write one yourself!
In my experience, it is not so difficult to modify a
generated .csproj . The major problem is that it
contains the scalar product of Platform-Configura-
tion conditions, and often more than that. The
first thing to do is to remove *all* tags with such
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
</PropertyGroup>
and insert, or better include, a simplified version,
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Platform)' == 'AnyCPU'"></PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'x86'"></PropertyGroup>
<PropertyGroup Condition="'$(Platform)' == 'x64'"></PropertyGroup>
<PropertyGroup>
<PlatformTarget>$(Platform)</PlatformTarget>
<OutputPath>bin\$(Configuration)\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
</PropertyGroup>
</Project>
upon which the file becomes small, clean, and main-
tainable.
I still like a small handwritten from scratch 5-10 lines .csproj
file better.

Arne

Loading...