Build on the Build Server Error: CS1730, After updating the Projects - msbuild

Step 1:
Do the edit for following to the *.*proj files
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.-->
<Target Name="BeforeBuild">
<Version VersionFile="..\VersionInfo.txt" RevisionType="Increment">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="Revision" />
</Version>
<AssemblyInfo CodeLanguage="CS" OutputFile=".\Properties\AssemblyVersion.cs" AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)" AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" />
</Target>
<!--
<Target Name="AfterBuild">
</Target>
-->
Step 2:
Remove the AssemblyVersion number, and AssemblyFileVersion from the AssemblyInfo.cs
Step 3:
Create a file called VersionInfo.text outside where the sln resides.
Step 3:
Include the AssemblyVersionNumber.cs into the project's
Step 4:
Issue a MSBuild, Works fine on local machine, but not on the build server.
DevMachine: (32 bit)
C:\SVNHome\branches\MyGreatProject-II>msbuild -ver
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3643]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
BuildServer:
D:\SVNHome\branches\source\MyGreatProject-II>%windir%\Microsoft.NET\Framework64\v3.5\msbuild
-ver
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.4234]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Error Message given on the build server is not helping.
Properties\AssemblyInfo.cs: error CS1730: Assembly and module
attributes must precede all other elements defined in a file except
using clauses and extern alias declarations

Its my bad, Went on to the Server,
Undo all checkouts on the build Server
Force a build, then it worked fine.
Thank you Jessehouwing. That was it.

Related

MSBuild ClickOnce app: FTP Upload files after build

I am using MS build to publish my ClickOnce app, in Visual Studio 2017 developer command line to a remote ftp site.
How do I initiate the FTP file upload that starts in Visual Studio after build? This is my command line, which builds the project:
msbuild /target:publish -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\IIC\IIC.UI.vbproj"
There are 2 problems with command line Click Once deployment: (1) Auto Incrementing option from the publish property page of a project is not honored from the command line, and (2) the subject of the question, starting the FTP upload to the remote site.
Solution (with Visual Studio 2017 Developer Command Prompt v15.7.3)
Download community ms build tasks from here: https://github.com/loresoft/msbuildtasks
Unload the project and open with notepad++ or your editor of choice and import the community ms build tasks. Follow the instructions on their github page.
Add file ProjectName.version.txt with just one line with the version information of your project. For example:
1.2.78.1341
The numbers correspond to {Major}.{Minor}.{Build}.{ApplicationRevision}
Add the following target to the bottom of the project, which uses the Version and FileUpdate community tasks:
<Target Name="beforePublishCmd">
<Message Text="revision before: 3.0.0.$(ApplicationRevision)"/>
<Version VersionFile="ProjectName.version.txt" BuildType="Automatic" Major="3" Minor="0" Build="0" RevisionType="Increment">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="ApplicationRevision" />
</Version>
<Message Text="revision after: 3.0.0.$(ApplicationRevision)"/>
<FileUpdate Files="ProjectName.vbproj"
Regex="<ApplicationRevision>(\d+)"
ReplacementText="<ApplicationRevision>$(ApplicationRevision)" />
</Target>
Call the above target from the command line BEFORE calling the publish target, like so:
msbuild /target:beforePublishCmd -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\ProjectName.vbproj"
Add an "afterPublish" target, which uses the FtpUploadDirectoryContent community task. This target is automatically called after the publish target finishes.
<Target Name="afterPublish">
<PropertyGroup>
<CurrentDate>$([System.DateTime]::Now.ToString(yyyy MMM dd HH:mm:ss))</CurrentDate>
</PropertyGroup>
<FtpUploadDirectoryContent
ServerHost="projectname.org"
Username="*****"
Password="*****"
LocalDirectory=".\bin\Release\app.publish"
RemoteDirectory="/"
Recursive="true"
/>
<Exec Command="C:\Progra~1\TortoiseSVN\bin\svn commit ..\ --non-interactive --message "Release 3.0.0.$(Revision) on $(CurrentDate): $(commitMessage)""/>
</Target>
Finally, call the publish target from the command line:
msbuild /target:publish -property:Configuration=Release /p:PlatformTarget=x86 "%USERPROFILE%\VSProjects\ProjectName.vbproj"
MSBuild ClickOnce app: Upload files after build
You can add a copy task into your project file to upload files after build:
To accomplish this, unload your project. Then at the very end of the </project>, just before the end-tag, place below scripts:
<ItemGroup>
<UploadFiles Include="ThePathOfYourUploadFiles\*.*"/>
</ItemGroup>
<Target Name="AfterBuild">
<Copy
SourceFiles="#(UploadFiles)"
DestinationFolder="PathWhereYouWantTouploadYourUploadFiles"
/>
</Target>
With this target, Visual Studio/MSBuild will upload the files after build.
Hope this helps.

Invoke remote MSBuild script inside a MSBuild script with cygwin sshd

I'm trying to do some MSBuild automation for deploy and backup. I tried several different remote execution platforms (Powershell/WMI, PsExec and Cygwin) and had some troubles with all of them.
With Powershell and PsExec, I think the problem is some security baselines used on the machines. I don't have full control of the machines and domain.
The most stable scenario I found is with cygwin/openssh. But when I'm running plink inside MSBuild and trying to invoke MSBuild remotely, msbuild hangs without telling me the error. If I run directly plink from prompt, everything works fine.
The MSBuild script follows:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Plink>"c:\Program Files (x86)\PuTTY\plink.exe"</Plink>
<UserName></UserName>
<Password></Password>
<HostName>localhost</HostName>
<RemoteCommand2>/cygdrive/c/SandBox/remotemsbuild/echoalotoffiles.bat</RemoteCommand2>
</PropertyGroup>
<Target Name="Build">
<Exec Command="$(Plink) -l $(UserName) -pw $(Password) -batch $(HostName) $(RemoteCommand2)" />
</Target>
<Target Name="EchoALotOfFiles">
<ItemGroup>
<SandBoxFiles Include="$(MSBuildProjectDirectory)\..\**\*.*" />
</ItemGroup>
<Message Text="#(SandBoxFiles)" />
</Target>
</Project>
When I run the first target, Build, I have the issue (MSBuild hanging)
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.17929]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 02/11/2013 12:01:45.
Project "C:\SandBox\remotemsbuild\remotemsbuild.build" on node 1 (EchoALotOfF
iles target(s)).
EchoALotOfFiles:
If I run just plink from command line, everything works fine.
Any guesses?

Unable to find MSDeploy task within MSBuild

I am trying to use the MSDeploy task within MSBuild (instead of calling it form the command line). I assumed this task was built in to MSBuild but I seem to be having trouble finding the task. The error Im getting is below. I have just re-installed the Web Deploy Tool to see if it might help.
C:\CLIENTS\DAM\Components\Umbraco\SiteTemplate_v6_1_6\Build>msbuild MSBuildScript.csproj -t:Deploy_v2
Microsoft (R) Build Engine version 4.0.30319.17929
[Microsoft .NET Framework, version 4.0.30319.18052]
<!-- some other stuff -->
error MSB4036: The "MSDeploy" task was not found. Check
the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and imple
ments the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks
files located in the "c:\Windows\Microsoft.NET\Framework\v4.0.30319" directory.
v10.0 can vary (v11.0 for example)
Do a search for your "Microsoft.WebApplication.targets" file and alter the import statement to match.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="AllTargetsWrapped">
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- Bunch of Other Stuff -->
<Target Name="AllTargetsWrapped">
<CallTarget Targets="ShowVariables" />
</Target>
<Target Name="ShowVariables" >
<Message Text="MSBuildExtensionsPath = $(MSBuildExtensionsPath)" />
</Target>

GetAssemblyIdentity Version always 1.0.0.0

The Version is 1.0.0.0 even though both the file version and product version are defined in the DLL and display correctly when I view its properties in Windows 7. Any suggestions?
<Target Name="TestingAssemblyIdentity">
<GetAssemblyIdentity AssemblyFiles="MyCSharp.dll">
<Output TaskParameter="Assemblies" ItemName="assemblyInfo"/>
</GetAssemblyIdentity>
<Message Text="GetAssemblyIdentity Version is %(assemblyInfo.Version)" />
</Target>
The GetAssemlyIdentity task returns the assembly version (AssemblyVersionAttribute), not the file or product version. The later are not part of the assembly's identity.
Note that assembly version and assembly file/product version serve different purposes.
See here for a possible way to read the file version from within msbuild.

Running XUnit tests with TeamCity using MSBuild

I am trying to get TeamCity to run XUnit tests as part of the build process. So I created a separate file - MyProject.msbuild - living in the same folder as the .sln file, which looks like this:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask AssemblyFile="$(MSBuildProjectDirectory)\..\bin\xunit.net\xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit"
/>
<Target Name="Build">
<MSBuild Projects="MyProject.sln" Targets="Build" Properties="Configuration=Release">
<xunit Assembly="MyProject.Utility.Tests\bin\Release\MyProject.Utility.Tests.dll" />
</MSBuild>
</Target>
</Project>
However, no matter what I do, VS2010 hates me having the element inside the element. If I run MSBuild on the file, it tells me a little bit more:
P:\MyProject\src>c:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe MyProject.msbuild /tv:4.0 /v:d
Microsoft (R) Build Engine Version 4.0.30319.1
[Microsoft .NET Framework, Version 4.0.30319.225]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 08.11.2011 21:08:46.
Project "P:\MyProject\src\MyProject.msbuild" on node 1 (default targets).
Building with tools version "4.0".
P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.
Done Building Project "P:\MyProject\src\MyProject.msbuild" (default targets) -- FAILED.
Build FAILED.
"P:\MyProject\src\MyProject.msbuild" (default target) (1) ->
P:\MyProject\src\MyProject.msbuild(8,9): error MSB4067: The element <xunit> beneath element <MSBuild> is unrecognized.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:00.01
So my current guess is that it doesn't successfully load the xunit.runner.msbuild.dll somehow - or I have done something else strange.
However, I would think that if it couldn't load xunit.runner.msbuild.dll, it would tell me about it. I made sure the file is not blocked (by unpacking the xunit distribution with 7zip).
Any ideas what I can do to get MSBuild to swallow my build file and run the tests?
You don't want to nest the calls, try this:
<Target Name="Build">
<MSBuild Projects="MyProject.sln" Targets="Build" Properties="Configuration=Release">
</MSBuild>
<xunit Assembly="MyProject.Utility.Tests\bin\Release\MyProject.Utility.Tests.dll" />
</Target>
The items within a target are executed in sequence.